[ENH][GOODIE] Easy finalization
Andreas Raab
andreas.raab at gmx.de
Mon May 19 18:31:44 UTC 2003
[Repost as ENH]
Cheers,
- Andreas
> -----Original Message-----
> From: Andreas Raab [mailto:andreas.raab at gmx.de]
> Sent: Monday, May 19, 2003 8:27 PM
> To: 'The general-purpose Squeak developers list'
> Subject: RE: testinterpreterplugin and primitive cleaning?
>
>
> > > Andreas has already described how to call a finalizer on
> > > the Smalltalk side. This would then call a primitive that
> > > would take the ByteArray containing the handle and pass it
> > > back to the library cleanup routine.
> >
> > And a nice description for sure. It feels weird to live in a
> > land without destructors ;)
>
> But if you want to you can get really close ;) Attached are
> some changes which make it easier to deal with finalization
> from a users POV:
>
> "Change Set: EasyFinalization
> Date: 19 May 2003
> Author: Andreas Raab
>
> Support for easier finalization. In order to finalize an object use:
>
> someObject toFinalizeSend: aSelector to: aFinalizer
> with: aResourceHandle.
>
> For example
> Object new toFinalizeSend: #show: to: Transcript with:
> 'bye bye'.
>
> Note that an object cannot finalize itself (as Squeak
> provides post-mortem finalization) so you need a third party
> to do it. Often, the class of the object you are finalizing
> is the right place to put this. In addition, neither the
> finalizer nor the resource handle may reference the object
> directly as this would prevent the object from being garbage
> collected.
>
> A more typical example would be along the lines of:
>
> StandardFileStream>>open
> ... open the file here ...
> self toFinalizeSend: #closeHandle: to: self class with:
> fileHandle.
>
> Note that we can also unregister the object, e.g., do something like
>
> StandardFileStream>>close
> ... close the file here ...
> self finalizationRegistry remove: self ifAbsent:[].
>
> in order to prevent 'accidentally' closing the resource in
> finalization.
> "
>
> Cheers,
> - Andreas
>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: EasyFinalization.1.cs
Type: application/octet-stream
Size: 3711 bytes
Desc: not available
Url : http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20030519/9b02f54f/EasyFinalization.1.obj
More information about the Squeak-dev
mailing list
|