[quickjs-devel] Re: Defining a finalizalizer for an object

  • From: ian <ian@xxxxxxxxx>
  • To: quickjs-devel@xxxxxxxxxxxxx
  • Date: Thu, 9 Jan 2020 20:56:26 +0100

Hi
I have to figure the same problem using Java designing a language : I
used to count the number of my own objects, and then, from java 11, it
complains about the deprecation of the finalise() method overloading. I
believe it comes from the new gc procedures (the reading of december
java mag could be of interest....).

I'm no sure of the right way to go through this, but if any not so bad
idea, I will share it.


Regards

ian

Le 09/01/2020 à 20:45, Koushik Dutta a écrit :

It's not possible to do it for an arbitrary object, as far as I know.
But my workaround is to create a custom class that is a "finalizer
object", and then attach as a (hidden) property to any arbitrary
object. I can then use the finalizer object to observe when the
arbitrary object gets collected. The finalizer object gets collected
at the same time as the arbitrary object; just ensure that the
finalizer object is only referenced by that object.

Koush

On Thu, Jan 9, 2020 at 11:26 AM Eduard Suica
<dmarc-noreply@xxxxxxxxxxxxx <mailto:dmarc-noreply@xxxxxxxxxxxxx>> wrote:

    Is possible to define a finalizer/destructor for an object?
    Something like Duktape's fin function:

    .fin(object, function(self) { ... } )

    From the documentation: "When defining a new JS class, it is
    possible to declare a finalizer which is called when the object is
    destroyed. ".

    Is this possible for an arbitrary object? If yes, how?

    Great project,
    GE.

-- 
-- ian@xxxxxxxxx
-- Développeur compulsif

Other related posts: