[pm-h] When to use "weaken"?

Michael R. Davis mrdvt92 at yahoo.com
Thu Jan 23 14:07:23 PST 2014


Perl Folks,
I've never really used Perl for processes that run for a very long time.  But, I'm moving around and processing data on the scale of millions and millions.  
 
My issue is that I have a memory leak somewhere.
 
I think it's in a statement like this.
 
my $profile=XXX::Profiles::Profile->new(name=>$name, parent=>$self);

where it is important for the child object to know who's it's parent is.  But, I guess the garbage collector is not cleaning this up when both the parent and child go out of scope.
 
I don't think this is a "circular" reference (I called it a tree; like family tree) but it's all I've got as to an inkling of an idea of where my memory leak might be.
 
Is this the use case for weaken?  If so, where would you put the weaken statement, in the parent or the child.
 
for example in parent 
 
weaken $profile->{"parent"}; #but now the parent has to know about the internals of the child
 
in the child
 
sub new {
...
 weaken $self->{"parent"} if (exists($self->{"parent"}) and ref($self->{"parent"})); #don't want to auto vivify.
}
 
Am I correct in thinking this is a use case of weaken at all?
 
It also bothers me that Fedora appears to not get all of the memory back after the Perl process terminates.  Is that common?
 
Thanks,
Mike
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.pm.org/mailman/private/houston/attachments/20140123/4ce19fe2/attachment.html>


More information about the Houston mailing list