On Wed, 04 Jun 2008 15:20:05 +0200, Rob Rothwell wrote:

On Wed, Jun 4, 2008 at 8:41 AM, Klaus D. Witzel wrote:

{'this ', 'and ', 'that'} collect: [:each | ].
Smalltalk garbageCollect.
{thisContext tempAt: 1} inspect

first line: create some object and make a temp var point to it.
second line: invoke GC.
third line: see what's still pointed to by the temp var.



So...if I do line 1, then line 3, should I see items in the Array, or just the Array itself.

What you want to see (according to your question about object removal) is just the empty array; and what I wanted to point out (without hair-splitting ;) is, that when you GC+check this within the same method, it *must* fail.

In Smalltalk it's very easy to script the removal+GC+check, for example in a workspace or add GC+check temporarily in a debugger session; that was my concern.

This is all very interesting, because in my application I am creating lots
of collections of objects maintaining parent/child pointers, and I have
obviously just done it WRONG!

A good example for maintaining parent/child objects, which works perfectly, is Smalltalk's #addSubclass: #removeSubclass: (both on the instance side of Class); when you check these two methods think that 'superclass' is your parent pointer.

Chasing pointers and objects is showing me that when I remove objects from
my collections, I need to do that "all the way down," I think...

Thank you for helping my brain move in the right direction.

Rob


_______________________________________________
Beginners mailing list
Beginners@lists.squeakfoundation.org
http://lists.squeakfoundation.org/mailman/listinfo/beginners

Reply via email to