>>finalize questions

Michael van der Gulik squeakml at gulik.co.nz
Sun Aug 27 04:50:01 UTC 2006


Bert Freudenberg wrote:
> Michael van der Gulik schrieb:
> 
>> Bert Freudenberg wrote:
>>
>>> Michael van der Gulik schrieb:
>>
>> 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.
> 
> 
> You should try to trace the non-GCed instance of TestPoller. My guess 
> would be that it is still referenced by the #startPolling: method 
> context which is referenced by the process that executes the block you 
> forked.

You are right. In fact, the strong reference was sitting right there in 
front of me as a method parameter (/me slaps forehead).

For completeness, a working version of the code is attached. However, 
I've refactored the need for it away, so it's essentially useless now :-}.

Michael.
-------------- next part --------------
'From Squeak3.8 of ''5 May 2005'' [latest update: #6665] on 26 August 2006 at 5:19:53 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/24/2006 22:46'!
startPollingOnWeakArray: w
	| keepPolling |
	keepPolling := true.
	[ [keepPolling] whileTrue: [
		" Try very hard to get x garbage collected:"
		((w at: 1) isNil) ifTrue: [keepPolling := false] ifFalse: [ (w at: 1) poll ].
		Smalltalk garbageCollectMost.
	] ] forkNamed: 'Bleeper'.
! !

!TestPoller class methodsFor: 'as yet unclassified' stamp: 'mvdg 8/24/2006 22:31'!
startPolling: obj
	self startPollingOnWeakArray: (WeakArray with: obj).
	" Need to call another method because otherwise we'd be holding an immutable reference to obj. "! !


More information about the Squeak-dev mailing list