I'm experiencing behavior that was not expected, and I'm wondering if this is "normal".
I have a "session" object that has a "has a" relationship with CGI::Session.
If I make sure to undef my object before the program ends, then everything is fine.
However, if I don't specifically undef my session object... and instead rely on the default garbage collection... it looks like the CGI::Session object I'm using gets destroyed BEFORE my session object gets destroyed.
It would seem to me that there should still be a reference count to the CGI::Session object as long as my object exists and that my session object would be destroyed first. Isn't this the way it is supposed to happen?
I managed to squeak out a diagnostic message that said
DESTROY created new reference to dead object
Can't call method "param" on an undefined value...
Re:Is it at interpreter shut down?
phillup on 2004-11-12T00:29:26
Yes, it is when the program ends.
Interestingly, if I have something like this then everything is OK.But, if I do something like this then I see the error message.#!/usr/bin/perl
use strict;
use warnings;
use My::Session;
my $session = new My::Session;
print $session->valid() ? "Session is valid\n" : "Session is NOT valid\n";Notice that the variable $session is referenced in the sub, but the sub isn't called. I think it might be closure related but I don't know enough about closures to be sure...#!/usr/bin/perl
use strict;
use warnings;
use My::Session;
my $session = new My::Session;
sub skipme{
my $id = $session->id();
print "ID: $id\n";
}
print $session->valid() ? "Session is valid\n" : "Session is NOT valid\n";
The second one is very close to my test case. I'm currently paring down the My::Session (not it's real name;-)) module to simplify things as much as possible.
It certainly seems like Perl should just "Do the right thing" in this case.