[Newbies] What is a "weak" reference

Rob Rothwell r.j.rothwell at gmail.com
Mon Jul 14 16:51:39 UTC 2008


On Mon, Jul 14, 2008 at 11:42 AM, Todd Blanchard <tblanchard at mac.com> wrote:

> So how do you make a weak reference? You stick a WeakArray in as a holder.
>  So in your parent/child objects you would write something like:
>
> Node>>parent
>        ^ parent ifNotNil: [parent first] ifNil: [parent]
>
> Node>>parent: p
>        parent := p ifNotNil: [WeakArray with: p] ifNil: [p]
>
> thus using a WeakArray as a holder for the parent.
>
> When a weak reference gets garbage collected, its weak references are set
> to nil first.


Thank you!  This is what I wanted to know; I'll give this a try, and see how
it works for me...

So many Classes, so little time...

Rob
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.squeakfoundation.org/pipermail/beginners/attachments/20080714/d3e962f5/attachment.htm


More information about the Beginners mailing list