macro_rules! track_var_owned {
($var:expr) => { ... };
}
Expand description
[ADVANCED] Track a variable with full lifecycle management and ownership transfer.
This macro creates a tracking wrapper that takes ownership of the variable and provides automatic lifecycle tracking with precise timing measurements. The wrapper includes robust drop protection to prevent duplicate tracking and enhanced smart pointer detection for accurate analysis.
§✅ Use this when:
- You need precise lifecycle tracking with automatic cleanup detection
- You want to measure exact variable lifetimes
- You’re doing advanced memory analysis or debugging
- You’re tracking variables that will be consumed/moved anyway
- You need the wrapper’s additional methods (get(), get_mut(), into_inner())
- You’re working with smart pointers (Rc, Arc, Box) that need special handling
§❌ Don’t use this when:
- You need to continue using the original variable (use
track_var!
instead) - Performance is critical and you don’t need lifecycle timing
- You’re tracking many variables (clone overhead)
- You’re doing basic memory profiling
§🛡️ Safety Features:
- Drop Protection: Prevents duplicate destruction tracking even if
into_inner()
is used - Smart Pointer Detection: Automatically detects and handles Rc, Arc, and Box types
- Error Resilience: Uses panic-safe error handling to prevent drop failures
- Atomic Protection: Thread-safe duplicate tracking prevention
§⚠️ Performance Note:
This macro takes ownership of the variable. If you need the original variable afterwards, you’ll need to clone it first, which has performance implications.
§Example
use memscope_rs::track_var_owned;
let my_vec = vec![1, 2, 3, 4, 5];
let tracked_vec = track_var_owned!(my_vec); // Takes ownership
```text
// This macro takes ownership of the variable