Subject: | Circular reference in data structure leads to memory leak |
Hi!
I may be using the module in bad/unexpected ways in
Devel::CoverX::Covered, but I recently encountered a problem with the
data structure in the Devel::Cover::DB object.
It seems there are circular references in it that prevents it from being
garbage collected when the object goes out of scope. Devel::Leak::Object
identified a number of objects still in memory at program termination.
(and doing that for large cover runs (around 500K cover/runs db files)
leads to Perl dying from Out of memory after 3-5 of them.)
My quick-n-dirty workaround to this problem is to do do
delete $cover_db->{cover};
on the Devel::Cover::DB object after I'm finished working with it. That
way it seems no take all its data with it when the object goes out of scope.
While Dumping the data structure shows some references to itself I can't
really tell exactly why my workaround works since there are no extra
references directly to $cover_db->{cover}. Maybe you'll have a better
idea, knowing the code base and data structure better. Presumably a
"weaken" in the correct place would take care of this.
Again, maybe I'm just using the module the wrong way.
/J