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

Todd Rinaldo todd at rinaldo.us
Thu Jan 23 20:44:29 PST 2014


Wade's advice is good so I don't have much to add to the fix.

My 2 cents is that in past when I've had to use weaken, it usually
points to a design issue or a paradigm I've not gotten with my code.
If possible, you might ask if you could change your class layout to
avoid this problem. YMMV.

It also sounds like an interesting problem. Would you be interested in
talking about it at the meeting next month?

On Thu, Jan 23, 2014 at 10:30 PM, 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.
>
>>
>> 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
>
> Thanks,
> Mike
>
> mrdvt92
> _______________________________________________
> Houston mailing list
> Houston at pm.org
> http://mail.pm.org/mailman/listinfo/houston
> Website: http://houston.pm.org/



-- 
Todd Rinaldo
todd at rinaldo.us


More information about the Houston mailing list