[Newbies] What is a "weak" reference

Michael van der Gulik mikevdg at gmail.com
Tue Jul 15 09:39:20 UTC 2008


On Mon, 14 Jul 2008 12:07:51 +0200
"Michael Davies" <mykdavies+squeak at gmail.com> wrote:

> On Sun, Jul 13, 2008 at 6:15 PM, Rob Rothwell <r.j.rothwell at gmail.com> wrote:
> > Can someone explain what a "weak" vs (I am guessing) "strong" reference is?
> [snip]
> > I, too, am maintaining parent/child relationships in my application and have
> > just been doing something like:
> > Parent>>createChild
> >      |child|
> >      child := Child new parent: self.
> >      ^child
> > I am assuming, given my troubles, that this is NOT a weak reference?!
> 
> Hi Rob,
> Have a look at the class comment on WeakArray: "WeakArray is an array
> which holds only weakly on its elements. This means whenever an object
> is only referenced by instances of WeakArray it will be garbage
> collected."
> 
> My understanding of this is that garbage collection is done by
> reference counting, and so the situation you described may result in
> parent and child forming a circular reference to each other, and so
> never being collected - but it depends on what you do with that return
> value.

Squeak's garbage collector is a generational mark/sweep garbage collector. It does not use reference counting.

http://wiki.squeak.org/squeak/1469 (unfortunately the page has a dead URL in it).

Gulik.


-- 
Michael van der Gulik <mikevdg at gmail.com>


More information about the Beginners mailing list