object finalization

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

object finalization

Alex Schenkman
Hi List:

Is there a method being called right befire an object is being garbage collected (finalized)?
I see toFinalizeSend: to: with:, but I do not see any senders.

thanks in advance!
Reply | Threaded
Open this post in threaded view
|

Re: object finalization

Igor Stasenko
On 26 August 2011 16:29, Alex Schenkman <[hidden email]> wrote:
> Hi List:
> Is there a method being called right befire an object is being garbage
> collected (finalized)?
> I see toFinalizeSend: to: with:, but I do not see any senders.
> thanks in advance!

Squeak finalization is a post-mortem finalization. The #finalize
message are sent to executor object,
which is often a shallow copy of the object which is died.


--
Best regards,
Igor Stasenko AKA sig.

Reply | Threaded
Open this post in threaded view
|

Re: object finalization

Alex Schenkman
Let's see if I get this right:

obj := Object new.
objExecutor := obj executor.
obj := nil.
Smalltalk garbageCollect.

Will this execute the method finalize on objExecutor?
Is this the way to use it?

Thanks!

On Friday, August 26, 2011 at 5:53 PM, Igor Stasenko wrote:

On 26 August 2011 16:29, Alex Schenkman <[hidden email]> wrote:
Hi List:
Is there a method being called right befire an object is being garbage
collected (finalized)?
I see toFinalizeSend: to: with:, but I do not see any senders.
thanks in advance!

Squeak finalization is a post-mortem finalization. The #finalize
message are sent to executor object,
which is often a shallow copy of the object which is died.


--
Best regards,
Igor Stasenko AKA sig.

Reply | Threaded
Open this post in threaded view
|

Re: object finalization

Luc Fabresse
Hi Alex,

Here what I understood:

    o := Object new.
    WeakRegistry default add: o. "a shallow copy of o is registered"
    o := nil.
    Smalltalk garbageCollect.
    "the shallow copy of o will receive the finalize message"

Cheers,

#Luc



2011/8/26 Alex Schenkman <[hidden email]>
Let's see if I get this right:

obj := Object new.
objExecutor := obj executor.
obj := nil.
Smalltalk garbageCollect.

Will this execute the method finalize on objExecutor?
Is this the way to use it?

Thanks!

On Friday, August 26, 2011 at 5:53 PM, Igor Stasenko wrote:

On 26 August 2011 16:29, Alex Schenkman <[hidden email]> wrote:
Hi List:
Is there a method being called right befire an object is being garbage
collected (finalized)?
I see toFinalizeSend: to: with:, but I do not see any senders.
thanks in advance!

Squeak finalization is a post-mortem finalization. The #finalize
message are sent to executor object,
which is often a shallow copy of the object which is died.


--
Best regards,
Igor Stasenko AKA sig.


Reply | Threaded
Open this post in threaded view
|

Re: object finalization

Igor Stasenko
Luc won the prize :)

Alex, you understood almost right, except a missing part of adding an
object to weak registry:

obj := Object new.
objExecutor := obj executor.
>>> WeakRegistry default add: obj executor: objExecutor.
obj := nil.
Smalltalk garbageCollect.

if you look at default implementation of #executor, it just does a
shallow copy of receiver.
This is why two lines:

objExecutor := obj executor.
 WeakRegistry default add: obj executor: objExecutor.

equivalent to just:

WeakRegistry default add: obj

On 26 August 2011 21:18, Luc Fabresse <[hidden email]> wrote:

> Hi Alex,
>
> Here what I understood:
>
>     o := Object new.
>     WeakRegistry default add: o. "a shallow copy of o is registered"
>     o := nil.
>     Smalltalk garbageCollect.
>     "the shallow copy of o will receive the finalize message"
>
> Cheers,
>
> #Luc
>
>
>
> 2011/8/26 Alex Schenkman <[hidden email]>
>>
>> Let's see if I get this right:
>> obj := Object new.
>> objExecutor := obj executor.
>> obj := nil.
>> Smalltalk garbageCollect.
>> Will this execute the method finalize on objExecutor?
>> Is this the way to use it?
>> Thanks!
>>
>> On Friday, August 26, 2011 at 5:53 PM, Igor Stasenko wrote:
>>
>> On 26 August 2011 16:29, Alex Schenkman <[hidden email]> wrote:
>>
>> Hi List:
>> Is there a method being called right befire an object is being garbage
>> collected (finalized)?
>> I see toFinalizeSend: to: with:, but I do not see any senders.
>> thanks in advance!
>>
>> Squeak finalization is a post-mortem finalization. The #finalize
>> message are sent to executor object,
>> which is often a shallow copy of the object which is died.
>>
>>
>> --
>> Best regards,
>> Igor Stasenko AKA sig.
>>
>
>



--
Best regards,
Igor Stasenko AKA sig.