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.
- Fix GC handling during
each_object(it was incorrectly inverted).
- Ensure all
FREEOBJevents are enqueued. - Allow limited re-entrancy in queue processing.
- Add
track_alloption toSampler.
- Add
Capture#track_allwhich defaults to false.
- Improve performance of object table.
- Add
Capture#each_objectfor getting all retained objects. - Add
retained_addresses:option toSampler#analyzeto capture addresses. - Add
Sampler#analyze(retained_minimum: 100)- if the retained_size is less than this, the analyse won't proceed. - Remove
Memory::Profiler::Graph- it's too slow for practical use. - Add
Memory::Profiler.address_of(object)to get the memory address of an object.
- Implement Cooper-Harvey-Kennedy algorithm for finding root objects in memory leaks.
- Rework capture to track objects by
object_idexclusively.
- 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.
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.