Squeak
  links to this page:    
View this PageEdit this Page (locked)Uploads to this PageHistory of this PageTop of the SwikiRecent ChangesSearch the SwikiHelp Guide
Garbage Collection and Semaphore
Last updated at 3:44 pm UTC on 14 January 2006
From: Michael Roberts Sent: January 22, 2004 Subject: Sockets and finalization [Garbage collection points]

What is the best, or considered, way to handle processes in objects when you then forget about the object without cleaning up the process? If you have a process blocking on a semaphore I assume that it will never be GCd because, at least, the scheduler has got a hold of it. So should I also be looking at finalisation here?


From: Andreas Raab
It depends. A process blocking on a semaphore WILL get GCed if the associated semaphore gets GCed. For example:
| process sema weakObserver |
sema := Semaphore new.
process := [sema wait] forkAt: Processor userInterruptPriority.
weakObserver := WeakArray with: process.
"No GC both semaphore and process"
process := sema := nil.
Smalltalk garbageCollect.
"lo and behold! it's gone"
weakObserver first.
So if you'd have a process blocking on a semaphore in a socket, all of socket, semaphore and process are likely to "go away" at the same time.