Efficient memory allocation tracking focused on retained objects only. Automatically tracks allocations and cleans up when objects are freed, giving you precise data on memory leaks.
- Retained Objects Only: Uses
RUBY_INTERNAL_EVENT_NEWOBJandRUBY_INTERNAL_EVENT_FREEOBJto automatically track only objects that survive GC. - O(1) Live Counts: Maintains per-class counters updated on alloc/free - no heap enumeration needed!
- Tree-Based Analysis: Deduplicates common call paths using an efficient tree structure.
Please see the project documentation for more details.
-
Getting Started - This guide explains how to use
memory-profilerto automatically detect and diagnose memory leaks in Ruby applications. -
Rack Integration - This guide explains how to integrate
memory-profilerinto Rack applications for automatic memory leak detection.
Please see the project releases for all releases.
- Breaking: Renamed
Capture#count_fortoCapture#retained_count_offor better clarity and consistency. - Breaking: Changed
CallTree#top_paths(limit)toCallTree#top_paths(limit:)- now uses keyword argument. - Breaking: Changed
CallTree#hotspots(limit)toCallTree#hotspots(limit:)- now uses keyword argument. - Simplified
Sampler#analyzereturn structure to{allocations: {...}, call_tree: {...}}format. - Added
Allocations#as_jsonandAllocations#to_jsonmethods for JSON serialization. - Added
CallTree#as_jsonandCallTree#to_jsonmethods for JSON serialization with configurable options. Memory::Profiler::Allocations.newcan now be instantiated directly (primarily for testing).Sampler#statisticsis now a deprecated alias forSampler#analyze.- Breaking: Removed
Sampler#all_statisticsmethod.
- Enable custom
depth:andfilter:options toSampler#track. - Change default filter to no-op.
- Add option to run GC with custom options before each sample to reduce noise.
- Always report sampler statistics after each sample.
- Ignore
freeobjfor classes that are not being tracked.
- Ignore
freeobjevents for objects with anonymous classes that are not tracked (and thus becomeT_NONE).
- Fix sampler loop interval handling.
- Log capture statistics from sampler run loop.
- Use
rb_obj_idfor tracking object states to avoid compaction issues.
- Double buffer shared events queues to fix queue corruption.
- Added
Capture#new_count- returns total number of allocations tracked across all classes. - Added
Capture#free_count- returns total number of objects freed across all classes. - Added
Capture#retained_count- returns retained object count (new_count - free_count). - Critical: Fixed GC crash during compaction caused by missing write barriers in event queue.
- Fixed allocation/deallocation counts being inaccurate when objects are allocated during callbacks or freed after compaction.
Capture#clearnow raisesRuntimeErrorif called while capture is running. Callstop()beforeclear().
- More write barriers...
- Use single global queue for event handling to avoid incorrect ordering.
We welcome contributions to this project.
- Fork it.
- Create your feature branch (
git checkout -b my-new-feature). - Commit your changes (
git commit -am 'Add some feature'). - Push to the branch (
git push origin my-new-feature). - Create new Pull Request.
In order to protect users of this project, we require all contributors to comply with the Developer Certificate of Origin. This ensures that all contributions are properly licensed and attributed.
This project is best served by a collaborative and respectful environment. Treat each other professionally, respect differing viewpoints, and engage constructively. Harassment, discrimination, or harmful behavior is not tolerated. Communicate clearly, listen actively, and support one another. If any issues arise, please inform the project maintainers.