On Fri, Aug 6, 2021 at 2:41 PM J <zon8resea...@gmail.com> wrote:
>
> Using embedded v8, I'm trying to clear the current variables and functions.
>
> I've found that in order to save having to recreate the isolate, which can be 
> quite slow, I can just create a new context from the isolate. However, the 
> old context still exists in memory and its not needed.
>
> How can I delete an old context now that I don't need it?
>
> Example code snippet:
>
> ```
> // Creates a new execution environment containing the built-in
> // functions.
> v8::Local<v8::Context> CreateShellContext(v8::Isolate* isolate) {
>   // Create a template for the global object.
>   v8::Local<v8::ObjectTemplate> global = v8::ObjectTemplate::New(isolate);
>   // Bind the global 'print' function to the C++ Print callback.
>   global->Set(isolate, "print", v8::FunctionTemplate::New(isolate, Print));
>   // Bind the global 'read' function to the C++ Read callback.
>   global->Set(isolate, "read", v8::FunctionTemplate::New(isolate, Read));
>   // Bind the global 'load' function to the C++ Load callback.
>   global->Set(isolate, "load", v8::FunctionTemplate::New(isolate, Load));
>   // Bind the 'quit' function
>   global->Set(isolate, "quit", v8::FunctionTemplate::New(isolate, Quit));
>   // Bind the 'version' function
>   global->Set(isolate, "version", v8::FunctionTemplate::New(isolate, 
> Version));
>   return v8::Context::New(isolate, NULL, global);
> }
> ```
>
> ```
>     v8::Local<v8::Context> context = CreateShellContext(isolate);
>     if (context.IsEmpty()) {
>       fprintf(stderr, "Error creating context\n");
>       return 1;
>     }
>     if (run_shell) RunShell(context, platform.get());
> ```

This question comes up every six months or so. If you search the
archives, you can probably find a longer discussion, but the short
answer is that you don't, it gets garbage collected when there are no
more references to it.

-- 
-- 
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/CAHQurc_suz7aMZbkfJqYZPSSf-vB11WPkBcyz3BvyVNbPssL3w%40mail.gmail.com.

Reply via email to