159 releases (19 breaking)

new 0.21.0-alpha.1 Dec 11, 2024
0.20.2 Nov 28, 2024
0.17.0 Jul 8, 2024
0.15.0-alpha.5 Mar 29, 2024
0.4.0 Mar 28, 2023

#92 in Profiling

Download history 9352/week @ 2024-08-25 7703/week @ 2024-09-01 7565/week @ 2024-09-08 6199/week @ 2024-09-15 7058/week @ 2024-09-22 3586/week @ 2024-09-29 4920/week @ 2024-10-06 6502/week @ 2024-10-13 4784/week @ 2024-10-20 4845/week @ 2024-10-27 6226/week @ 2024-11-03 6391/week @ 2024-11-10 6163/week @ 2024-11-17 5445/week @ 2024-11-24 7295/week @ 2024-12-01 6234/week @ 2024-12-08

25,531 downloads per month
Used in 48 crates (5 directly)

MIT/Apache

120KB
2K SLoC

Run-time memory tracking and profiling.

Part of the rerun family of crates.

Latest version Documentation MIT Apache

This is a library for tracking memory use in a running application. This is useful for tracking leaks, and for figuring out what is using up memory.

re_memory includes an opt-in sampling profiler for allocation callstacks. Each time memory is allocated there is a chance a callstack will be collected. This information is tracked until deallocation. You can thus get information about what callstacks lead to the most live allocations, giving you a very useful memory profile of your running app, with minimal overhead.


lib.rs:

Run-time memory tracking and profiling.

First steps

Add re_memory to your Cargo.toml:

cargo add re_memory

Install the AccountingAllocator in your main.rs:

use re_memory::AccountingAllocator;

#[global_allocator]
static GLOBAL: AccountingAllocator<std::alloc::System>
    = AccountingAllocator::new(std::alloc::System);

Checking memory use

Use MemoryUse::capture to get the current memory use of your application.

Finding memory leaks

Turn on memory tracking at the top of your main() function:

re_memory::accounting_allocator::set_tracking_callstacks(true);

Now let your app run for a while, and then call accounting_allocator::tracking_stats to get the statistics. Any memory leak should show up in TrackingStatistics::top_callstacks.

More

See also accounting_allocator.

Dependencies

~2–29MB
~418K SLoC