Hello,

I am having 'problems' with a library for retrieving and saving objects from/to and relational database using DBI. The design in similar to, but simpler than the way that J2EE works.

My problem is this:
The main class in the whole library basically wraps a DBI connection to a database and provides additional services like object caching and maintaining uniqueness of objects based on their primary key fields. By default the 'gateway' object uses transactions and does a rollback when it is destroyed - this is so that you need to explicitly commit for your changes to take place. The problem is that if I use a global 'gateway' object it DESTROY method doesn't get called until the phase2 garbage collection. But if I don't use the global in any user defined subroutines it is cleaned up and the DESTROY method can successfully call rollback on the DBI handle.

The message I am getting otherwise is:

(in cleanup) cannot Can't call method "rollback" on an undefined value at /.../Gateway.pm line 94 during global destruction.

This is happening because the DBI object is gone when the DESTROY method of my gateway object is called. But this is curious because the gateway object has a reference to the DBI object.

If someone could point me to some detailed explanation of how GC works in perl I would greatly appreciate it - and please... I have read the perldocs and they are not sufficient.

Thanks - oyasuminasai

In reply to Global objects and GC by oyasuminasai

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.