The problem is that your object is in a global variable and so survives to global destruction. During global destruction Perl just goes and destroys things in an essentially random order.

This could be considered a bug in Perl (even though it was documented) and will be fixed in Perl 5.8. However note that the fix depends heavily upon the fact that Perl uses reference counting, and not true garbage collection. It would not be safe to assume that Perl 6 will necessarily have reliable support for expected destruction mechanics.

In Perl 5.6 you could work around the issue by keeping track of created objects through WeakRefs and then in an END block destroying everything that didn't clean itself up.

You might think that you could just have the ini object be responsible for cleaning itself up, regardless of whether you had a tied interface to it or not. Unfortunately data that it depends upon might be cleaned up before it is, leading to data corruption. So you are just moving the problem around, but to really solve it you need to guarantee that the destruction happens before global destruction is hit.


In reply to Re (tilly) 1: Tie & Destroy, OOP by tilly
in thread Tie & Destroy, OOP by Flame

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.