Garbage Collection catch-22 with blocks - Thanks

Peter Smet peter.smet at flinders.edu.au
Fri Jun 25 07:19:15 UTC 1999


Alan, this is great.

All I needed to do was add: aBlock beWeak
to my code, do the garbage collection, and lo
and behold, the block was gone. I had guessed
that 'pulling the receiver out of the block' was
going to be necessary at some stage, but
didn't really know how to go about it.

I will need to synchronize things, to ensure that the system doesn't try to
evaluate blocks where the gc has turned the receiver to nil. I initially
thought this was going to be really difficult, since the weakBlocks will
have weakReceivers all over the place. However, since my system already
synchronizes with the garbage collector, all I need to do is add the
weakReceivers into my registry. Whenever one is collected, my finalization
Process will ensure it's block is cleaned up simultaneously. If and when it
works I will post a new change set up on the wiki (under projects,
publish-subscribe).

Thanks again!

Peter

>Briefly, the solution involves defining a new subclass of MethodContext,
>called WeakMethodContext, that uses a WeakArray to hold on to the
>receiver.  A MethodContext will answer a new WeakMethodContext
>with the same state in response to the message #asWeakContext.
>Sending the message #beWeak to a BlockContext causes it to
>replace its "home" context with "homeContext asWeakContext."
>
>I tested this briefly, and it seems to work.





More information about the Squeak-dev mailing list