How can I delete an old v8::Context?

99 kali dilihat
Langsung ke pesan pertama yang belum dibaca

J

belum dibaca,
6 Agu 2021, 08.41.4206/08/21
kepadav8-users
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());
```


Ben Noordhuis

belum dibaca,
7 Agu 2021, 06.53.3207/08/21
kepadav8-users
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.
Balas ke semua
Balas ke penulis
Teruskan
0 pesan baru