I’m trying to fix my code to enable Perl to recover unneeded data by weakening references and breaking cycles.
I recently asked a question on How to access Perl ref counts and the answer has been working well for me.
For some of my objects, the reference count is > 1 and I don’t know why.
Is there a way for me to add a callback or something to help me know when a reference count is incremented? I want to know who is referencing an object.
Implement a
Devel::XXXpackage that inspects the refcounts of your objects?You could sprinkle
$Devel::Something::CHECK = 1statements at appropriate places throughout your code, or change the condition inDB::DBto run at regular intervals (e.g.,if (++$Devel::Something::CHECK % 100 == 0) {to inspect after every 100 statement evaluations).