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

G. Wade Johnson gwadej at anomaly.org
Fri Jan 24 07:09:36 PST 2014


On Thu, 23 Jan 2014 20:30:16 -0800 (PST)
"Michael R. Davis" <mrdvt92 at yahoo.com> wrote:

> G. Wade,
>  
> >> My issue is that I have a memory leak
> >> 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
> >
> > If I'm understanding you, that's the definition of a circular
> > reference.
> >
> >     parent -> child -> parent
> 
> Yep, that's exactly what I have.  I guess this Engineer needs to
> study up on that computer science lingo.

<grin/>If this engineer could do it, you know it's possible.


> > In this case, the parent owns the child and the child owns the
> > parent.
> >You should weaken the child's reference to the parent (because the
> > child doesn't own the parent.)
> > 
> > I would do the weaken in the the child. You are passing the parent
> > reference to the child. The child knows that it doesn't need to own
> > the parent reference, so the child should weaken the reference.
>  
> I will try weakening in the children.  
>  
> >> It also bothers me that Fedora appears to not get all of the memory
> >> back after the Perl process terminates.  Is that common? 
> 
> > How are you determining whether Fedora "gets all of the memory
> > back"?
> 
> `top -c` then "<" to sort by memory.
>  
> This appears to be this bug.  So, unrelated but hurts just the same.
>  
> https://bugzilla.redhat.com/show_bug.cgi?id=473547
> Bug 473547 - console-kit-daemon huge memory allocation 

G. Wade
-- 
Be a good ancestor.                                   -- Jonas Salk


More information about the Houston mailing list