Hello,

I am embedding V8 in my C++ application and I need to create multiple 
isolates from different background threads.

Here's my workflow:

1. Create an isolate in the main thread -> this must be a long living 
isolate (for the entire application lifetime)
2. Spawn multiple short living background threads.
3. Inside each background thread, create a new isolate using Isolate::New.
4. At the end of the thread, call isolate->Dispose.

My question is about properly disposing the short living isolates. I have 
noticed that if I call the isolate->Dispose() as a final instruction inside 
the background thread, chances are that subsequent calls to Isolate::New 
from other threads will return a pointer to an already disposed isolate. Ss 
a result of this reuse, I get heap-use-after free errors when I try to 
perform some operations on this isolate.

On the other hand, if I don't call isolate->Dispose() then each call to 
Isolate::New will return a fresh new pointer, but the memory claimed by 
this short living isolates will never be reclaimed and is leaking.

So what is the proper way to dispose the isolates? Should the Dispose call 
be made from the background thread in which the isolate was created, or I 
need to dispose it from the main thread (in which I have entered the main 
isolate). I have tried both approaches without luck.

-- 
-- 
v8-users mailing list
v8-users@googlegroups.com
http://groups.google.com/group/v8-users
--- 
You received this message because you are subscribed to the Google Groups 
"v8-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to v8-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/v8-users/01d26b9e-140a-4148-9c4a-1d0901091848%40googlegroups.com.

Reply via email to