Not exactly a memory leak.

The persistent handle does not belong to the context. It belongs to  
v8. v8 will collect garbage eventually, and when it does, even if  
there are no active contexts, that persistent handle's callback will  
be called.

The only catch is on program termination. Memory will not get leaked,  
as the operating system will clear all of the memory. Even resources,  
such as files left open, will be closed. However, with items such as  
std::ostreams, problems arise because the destructor must be called to  
flush the file to output; for this, it is required to keep a separate  
list of all open resources that need to be closed.

I had this problem when trying to write to a file from JavaScript, and  
created a little helper class that did most of the heavy lifting for me:
http://create.tpsitulsa.com/blog/2009/02/20/v8-application-exit-and-destructors/

Alex

On Mar 5, 2009, at 2:00 PM, Stephan Beal wrote:

>
> On Mar 5, 8:48 pm, Ondrej Zara <[email protected]> wrote:
>> I was struggling with a very similar issue; please 
>> seehttp://groups.google.com/group/v8-users/browse_thread/thread/3d4e7e80 
>> ...
>
> Quoting you from that article:
>
> -------
> I will probably file this as a bug, because it seems logical to me
> that when a JS context is destroyed, all data objects in it should get
> GC'ed. What is your opinion?
> ------
>
> That's a show-stopper bug, IMO. If the dtor is NEVER called, not even
> when the context closes down, that's simply a fatal error, IMO. i
> can't wrap any classes in good conscience if i know that their dtors
> (which are critical components in many C++ idioms) will never, ever,
> ever be called. i'm willing to live with indeterminate timing garbage
> collection, but the time must be finite - it must happen before v8
> simply abandons the object. Without such a guaranty, a Persistent
> handle is simply a glorified, guaranteed memory leak.
>
> :-!
>
> >

Alex Iskander, TPSi





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

Reply via email to