in reply to is there a way to ensure some code is the last thing that is run?
Hi morgon,
Based on your example code, would it be correct to assume that the problem is happening because of circular references? If so, then tracking those down might be a good start, it should lead you to the culprit code.
I looked into tracking circular references, unfortunately it seems that Devel::LeakTrace and Devel::LeakTrace::Fast don't compile on modern versions of Perl/glib, Devel::Leak seems a bit too low-level, and Devel::Cycle requires you to specify which variables to check for cycles, which can be difficult if you have lots of objects being created. So far, the "best" thing I have found seems to be Devel::Leak::Object, which can override bless.
Also, I fiddled around with Devel::Gladiator and has_circular_ref from Data::Structure::Util, which seems to support more types of data than Devel::Cycle. Note that it appears to be important to limit the inspection to those things that we're actually interested in, in this case objects - just blindly using it on everything that walk_arena() returns leads to errors, and I even got some segfaults at one point. But the following seems to work, at least on your example code:
use Devel::Gladiator qw/walk_arena/; use Data::Structure::Util qw/has_circular_ref/; use Scalar::Util qw/blessed/; sub find_all_cycles { my $all = walk_arena(); for my $sv (@$all) { # limit search to objects next unless blessed($sv); warn "Has circular references: $sv\n" if has_circular_ref($sv); } @$all=(); } END { find_all_cycles() }
Hope this helps,
-- Hauke D
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: is there a way to ensure some code is the last thing that is run?
by morgon (Priest) on Feb 03, 2017 at 15:03 UTC | |
by haukex (Archbishop) on Feb 03, 2017 at 17:03 UTC | |
by RonW (Parson) on Feb 06, 2017 at 20:03 UTC |