Hi Luc, Sean, Igor, I still don't think that is right (although I did not actually try to run your approach): you still make the block closure of the process refer strongly to the timer object. I tried it as follows (.st file included at the end): Object subclass: #TestTimer instanceVariableNames: 'counter interval' TestTimer>>#initialize interval := 5 seconds asDelay. counter := 0. self class start: (WeakArray with: self) TestTimer>>#tick interval wait. counter := counter + 1 TestTimer class>>#start: reference [ [ reference first isNil ] whileFalse: [ reference first tick ] ] forkAt: Processor userBackgroundPriority named: 'Test Timer' Sadly it still does not work, and I don't know why ;-) TestTimer new. 3 timesRepeat: [ Smalltalk garbageCollect ]. TestTimer allInstances You can see the timer count going up every 5 seconds when inspecting the instance, but you have to close the inspector otherwise that is another reference. Exploring strong pointers lists the WeakArray instance... Sven On 23 Apr 2013, at 16:01, Luc Fabresse <luc.fabresse@gmail.com> wrote:
Hi Sean,
We experienced that also with Noury and Jannik. The trick has been to extract the block in a class side method. Example:
Timer>>start process := self class createProcessFor: self
Timer class>>createProcessFor: aTimer ^[ aTimer value: aTimer value + 1.......] fork
Now:
t := Timer new start. t := nil
makes the process dispear as well. ok not really beautiful but it works ;-)
Cheers,
Luc
#Luc
2013/4/23 Igor Stasenko <siguctua@gmail.com> On 23 April 2013 14:17, Sean P. DeNigris <sean@clipperadams.com> wrote:
Igor Stasenko wrote
you don't need finalization.. just a weak reference. something like this:
array := WeakArray with: myObject.
[[ array first notNil] whileTrue: [ ...... ]] fork.
Timer>>start
| array | array := WeakArray with: self. process := [ [ array first notNil ] whileTrue: [ interval asDelay wait. self value: self value + 1. self announcer announce: (TimerValueChanged to: self value) ] ] fork.
Timer new start. Smalltalk garbageCollect.
The process is still there...
but what you expecting? you refer to 'self' multiple times. sure thing it cannot be GC-ed, neither process will die because of plenty of references on stack. Even block closure which you creating for fork will have home context which keeps reference to 'self', e.g. receiver.
I'm attaching (to Nabble) a screenshot of #pointersTo <http://forum.world.st/file/n4683095/Screen_Shot_2013-04-23_at_8.16.01_AM.png>
----- Cheers, Sean -- View this message in context: http://forum.world.st/Terminating-a-Process-when-an-object-dies-tp4683036p46... Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.
-- Best regards, Igor Stasenko.