>>finalize questions
Michael van der Gulik
squeakml at gulik.co.nz
Tue Aug 22 10:10:50 UTC 2006
Bert Freudenberg wrote:
> Michael van der Gulik schrieb:
>> I thought of a better option today: Create a "PollingService"
>> singleton. The process I needed was just meant to slowly poll something.
>>
>> Rather than doing "[[self doSomething] repeat ] fork", I could ask the
>> PollingService to poll me on a regular basis. The polling service
>> would have something like:
>>
>> PollingService>>pollObject: n
>> | o |
>> o := myWeakArray at: n.
>> [ o isNil ] whileFalse: [ o poll. o:= myWeakArray at: n. ].
>>
>> So that when the object is garbage collected, the thread would also
>> stop iterating. A very useful pattern!
>>
>> This could maybe even be done on the class side of that object.
>>
>> I hope the small amount of time between loop iterations is enough to
>> get the GC to make the weak reference nil.
>
>
> Unlikely. Once an object gets tenured, only a full GC will collect it:
>
> http://minnow.cc.gatech.edu/squeak/1469
Ahh... I'd like to confirm that my approach indeed doesn't work, even if
I stick a 'Smalltalk garbageCollect' in the middle of it. Argh.
Code attached, if you can be bothered looking at it.
> Do you really have random objects that are not owned by some specific
> object that could release them?
Well, probably. I've just had another idea that I'll try.
Michael.
-------------- next part --------------
'From Squeak3.8 of ''5 May 2005'' [latest update: #6665] on 22 August 2006 at 10:07:34 pm'!
Object subclass: #TestPoller
instanceVariableNames: 'delay'
classVariableNames: ''
poolDictionaries: ''
category: 'Playing'!
!TestPoller commentStamp: 'mvdg 8/22/2006 22:07' prior: 0!
Test a polling pattern I made. It doesn't work.
p := TestPoller new.
p := nil.
Now, the transcript should stop showing 'bleep'. If your image is important, you'll need to stop the Bleeper process.!
!TestPoller methodsFor: 'as yet unclassified' stamp: 'mvdg 8/22/2006 21:43'!
initialize
delay := Delay forSeconds: 1.
self class startPolling: self.! !
!TestPoller methodsFor: 'as yet unclassified' stamp: 'mvdg 8/22/2006 21:42'!
poll
Transcript show: 'bleep '.
delay wait.! !
"-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- "!
TestPoller class
instanceVariableNames: ''!
!TestPoller class methodsFor: 'as yet unclassified' stamp: 'mvdg 8/22/2006 22:04'!
startPolling: object
| w x |
w := WeakArray with: object.
x := w at: 1.
[ [x isNil] whileFalse: [
x poll.
" Try very hard to get x garbage collected:"
x := nil.
Smalltalk garbageCollect.
Processor yield.
x := w at: 1.
] ] forkNamed: 'Bleeper'.! !
More information about the Squeak-dev
mailing list
|