We should write a chapter on finalization but since I do not know it well (and I forget)...
igor will answer you.

Stef
On 2/8/14 13:16, Udo Schneider wrote:
All,

I just stumbled over something which thought was pretty easy - turned out it isn't as easy as I thought or I'm simply _______ (fill in expression of choice like "too dumb", "blind", etc.)

I have an object which starts a background process to do it's job. This object holds a reference to the running proccess in an instance variable.

My goal is to #terminate that proccess once the object isn't needed anymore (before GC).

Using WeakRegistry for the object itself doesn't work. E.g.

MyObject>>#initialize
    super initialize.
    WeakRegistry default register: self.
    myProcess := self startProcess.

MyObject>>#finalize
    myProcess terminate. "Doesn't work. myProcess is already nil"

I think this is due to all the ivars of the object already being nil when #finalize is begin called. As far as I read the code this is due to Object>>#executor returning a shallow copy of the object and thus being by intention ...

So how to proceed? Did I miss something obvious? Is overwriting #executor the way to go (in terms of "does it work" and "doesn't it break something")?

Best Regards,

Udo







Reply via email to