Den 13. maj 2010 19.38 skrev Seiji Sam Lee <[email protected]>:

>  Is it possible? Can I detect the destruction of an object and so liberate
> data into internal pointers (SetPointerInInternalField)?
>
>
>
> For example: if I have a FILE* into an internalField and user not close
> explicity the object (file.close()), and the script finish, where can I
> close the file?
>
> Maybe the response was “free all forgotten by user when the script finish”,
> but it is a dirty solution L
>
> Exists callbacks for GC (I know) but GC don’t show the object to be
> liberated.
>
>
>
> Thanks in advance.
>
I see that others have provided the answer (weak handles).

Beware that your weak handle callback will only be called when V8 does a big
garbage collection.  V8 only does a big garbage collection when its
heuristics are telling it that it is running out of memory.  If V8 doesn't
run out of memory then your object is not garbage collected and you won't
get a callback.  If you were relying on the callback to free a different
resource then you could run out of that resource (eg open file descriptors)
just because V8 has lots of memory and sees no need to do a GC.

In addition, when V8 exits it assumes that the process is about the exit.
 Since the OS will clean up the memory, V8 won't bother to do a GC and won't
call your callbacks.   Some people find this counterintuitive.  Perl appears
to do a GC on exit.  At least that was my conclusion on observing that a
fork followed by an exit takes a huge amount of time on a large perl
process.

-- 
Erik Corry

-- 
v8-users mailing list
[email protected]
http://groups.google.com/group/v8-users

Reply via email to