101 releases (14 breaking)

new 0.16.0 May 16, 2024
0.15.1 Apr 11, 2024
0.15.0-alpha.5 Mar 29, 2024
0.12.0-alpha.2 Dec 26, 2023
0.4.0 Mar 28, 2023

#176 in Memory management

Download history 973/week @ 2024-01-25 954/week @ 2024-02-01 979/week @ 2024-02-08 3599/week @ 2024-02-15 4169/week @ 2024-02-22 5557/week @ 2024-02-29 4776/week @ 2024-03-07 4684/week @ 2024-03-14 2890/week @ 2024-03-21 2847/week @ 2024-03-28 4088/week @ 2024-04-04 6110/week @ 2024-04-11 5286/week @ 2024-04-18 4771/week @ 2024-04-25 5128/week @ 2024-05-02 3880/week @ 2024-05-09

20,214 downloads per month
Used in 27 crates (5 directly)

MIT/Apache

110KB
1.5K 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
~402K SLoC