Implement a Devel::XXX
package that inspects the refcounts of your objects?
package Devel::Something;
# just emulating Devel::Trace here
# see http://cpansearch.perl.org/src/MJD/Devel-Trace-0.10/Trace.pm
sub DB::DB {
if ($Devel::Something::CHECK) {
my ($package, $file, $linenumber) = caller;
... inspect current refcounts
... if any have changed, print out the details
... including current package/file/linenumber
$Devel::Something::CHECK = 0; # disable until it's enabled again
}
}
1;
# my program
... do some stuff ...
$Devel::Something::CHECK = 1;
... do some more stuff ...
$Devel::Something::CHECK = 1;
$ perl -d:Something my_program.pl ...
You could sprinkle $Devel::Something::CHECK = 1
statements at appropriate places throughout your code, or change the condition in DB::DB
to run at regular intervals (e.g., if (++$Devel::Something::CHECK % 100 == 0) {
to inspect after every 100 statement evaluations).