[Q] Process termination / GC

Anthony Hannan ajh18 at cornell.edu
Mon Jul 28 20:25:10 UTC 2003


tblanchard at mac.com wrote:
> I'm working on making top level Bricks handle events in their own 
> processes by allowing them to provide their own event dispatcher which 
> contains a SharedQueue and a process to poll it.  So my dispatcher 
> initializer looks like:
> 
> 	queue := SharedQueue new.
> 	process := ([ [true] whileTrue: [self dispatchEvent: (self queue next) 
> with: (self owner) ] ] fork).
> 		
> The dispatcher is held in a WeakKeyDictionary keyed by the Brick so it 
> will go away on its own - and the owner Brick is held weakly as well.
> The dispatcher is added as a listener to the hand and removed the first 
> time it gets an event outside the Brick's bounds.  So as far as I can 
> tell, the only think keeping the dispatcher from being collected is its 
> Brick's existence.
> 
> Do I need to do anything to clean up the process?  Or, more 
> importantly, is the forked block going to prevent GC on the dispatcher?

A process is like any other object.  If it is not reachable from a global
(including Processor) then it will be garbage collected.  A process is only
held by Processor when it is running or ready to run.  Otherwise, it is
terminated, suspended, or waiting on a semaphore, and is free from any
globals, and thus can be garbage collected.  When waiting on a semaphore,
the semaphore itself holds the process, so the process can be GCed only if
the semaphore can also be GCed.  So, in your example above, if the
SharedQueue (which holds the semaphore) is free to be GCed then the
process waiting on it will be free to be GCed as well (if nothing else is
holding it back).  So you should be ok.

Cheers,
Anthony



More information about the Squeak-dev mailing list