Finalization

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

Finalization

Sean P. DeNigris
Administrator
I found the following list threads...

http://forum.world.st/Finalization-question-td1300962.html mentions #beFinalizable, which doesn't seem to exist. I guess it was just an example, but seems like it should be added, no?

In http://forum.world.st/object-finalization-td3771196.html Igor suggested that the key is to do:
WeakRegistry default add: obj.

This guarantees? that #finalize will be called when the object is garbage collected.

I'm asking regarding my recent work wrapping the FMOD sound library with NativeBoost. I'm thinking my NBExternalObjects should release their resources when no longer referenced. I want to say:
FmodSound>>#finalize
  self primReleaseSound: handle.

So I've pieced together that I would have to also write:
FmodSound>>new
  instance := super new
    whatever;
    beFinalizable;
    yourself.

Object>>#beFinalizable
  WeakRegistry default add: self.

Am I correct that:
1. The above code would cause the resource to be safely released when the sound object was garbage collected?
2. This approach would be a good way to manage these types of resources?

Any hints would be appreciated as to the best way to accomplish managing these...

Thanks!
Cheers,
Sean
Reply | Threaded
Open this post in threaded view
|

Re: Finalization

Igor Stasenko



On 29 November 2013 07:21, Sean P. DeNigris <[hidden email]> wrote:
I found the following list threads...

http://forum.world.st/Finalization-question-td1300962.html mentions
#beFinalizable, which doesn't seem to exist. I guess it was just an example,
but seems like it should be added, no?

In http://forum.world.st/object-finalization-td3771196.html Igor suggested
that the key is to do:
WeakRegistry default add: obj.

This guarantees? that #finalize will be called when the object is garbage
collected.

I'm asking regarding my recent work wrapping the FMOD sound library with
NativeBoost. I'm thinking my NBExternalObjects should release their
resources when no longer referenced. I want to say:
FmodSound>>#finalize
  self primReleaseSound: handle.

So I've pieced together that I would have to also write:
FmodSound>>new
  instance := super new
    whatever;
    beFinalizable;
    yourself.

Object>>#beFinalizable
  WeakRegistry default add: self.

Am I correct that:
1. The above code would cause the resource to be safely released when the
sound object was garbage collected?
yes
2. This approach would be a good way to manage these types of resources?

yes
Any hints would be appreciated as to the best way to accomplish managing
these...

See NBExternalResourceManager class comment
 
Thanks!



-----
Cheers,
Sean
--
View this message in context: http://forum.world.st/Finalization-tp4726046.html
Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.




--
Best regards,
Igor Stasenko.
Reply | Threaded
Open this post in threaded view
|

Re: Finalization

Sean P. DeNigris
Administrator
> #beFinalizable, which doesn't seem to exist. I guess it was just an example, but seems like it should be added, no?

Do you agree that #beFinalizable would be a nice addition? If so, I will open an issue...

Igor Stasenko wrote
> See NBExternalResourceManager class comment
So the point of using NBExternalResourceManager is that it adds session awareness to finalization so that one doesn't attempt to release invalid external resources from previous sessions, right?

I was also thinking that maybe FMOD should also have a shutDown: which collects all external resource objects and cleans them up. Does that sound like a good idea? Overkill?
Cheers,
Sean