Skip to content

Instantly share code, notes, and snippets.

Forked from jkeroes/perl-memory-modules
Created July 8, 2019 22:55
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Perl memory leaks resources
Tracking memory leaks:
Devel::Arena - sv_stats() returns arena structures used for SV allocation
* Devel::Cycle - find_cycle($ref) returns all cycles found in $ref and the perl variables they point to
Devel::Gladiator - walk Perl variable arena
Devel::Leak - deprecated by Devel::LeakTrace::Fast
Devel::LeakTrace - deprecated by Devel::LeakTrace::Fast
* Devel::LeakTrace::Fast - prints leaked SV's and line numbers at END.
Data::Structure::Util - has_circular_ref($ref) returns ref to link in $ref that is circular or false.
Test::LeakTrace - no_leaks_ok(), etc.
Test::Memory::Cycle - Based on Devel::Cycle, offers memory_cycle_ok(), etc.
Tracking XS memory leaks:
Devel::Peek - Core module that dumps perlguts info. The examples section has useful perlguts explanations.
Devel::Plumber - use gdb to find and report leaks
Devel::Valgrind::Client - related to Test::Valgrind.
Test::Valgrind - just tracks Newx and malloc-like, not perl objects.
Memory allocation size:
Devel::Size - print size with and without ref traversals.
* Devel::Size::Report - print full report of every ref in a var.
Devel::Events::Handler::ObjectTracker - track every blessed obj created or destroyed via object_bless() and object_destroy()
Devel::Leak::Object - track select or every blessed obj
Devel::LeakGuard::Object - derived from Devel::Leak::Object; adds leakguard { ... } closure.
Fixing memory leaks:
* Data::Decycle - can also decycle coderefs! weaken_deeply(), decycle_deeply(), recsub { ... } - leak free closures
Data::Structure::Util - circular_off($ref) - traverse $ref for cyclical refs and weaken them.
* Object::Destroyer - create sentries for objects and inform them what to do during destruction
Scalar::Util - weaken()
Sub::Recursive - anonymous memory leak free subs. mutually_recursive(), recursive()
Articles on leaks:
How to use Object::Destroyer:
PM leak article collection:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment