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


In reply to Re: is there a way to ensure some code is the last thing that is run? by haukex
in thread is there a way to ensure some code is the last thing that is run? by morgon

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.