title: v8::Context memory leaks
body: <p>I'm trying to develop nodejs module on C++ using v8.</p>
  
  <p>Here is source code.</p>
  
  <pre><code>#include &lt;node.h&gt;
  
  using namespace v8;
  
  void TestContext1(const FunctionCallbackInfo&lt;Value&gt;&amp; args) {
  
      Isolate* isolate = Isolate::New();
      {
          Isolate::Scope isolate_scope(isolate);
          V8::Initialize();
          Locker lock(isolate);
  
          HandleScope handle_scope(isolate);
  
          Local&lt;Context&gt; context = Context::New(isolate);
          Context::Scope context_scope(context);
  
  
          Handle&lt;String&gt; strExpr = Handle&lt;String&gt;::Cast(args[0]);
          Handle&lt;Script&gt; script;
          Handle&lt;Value&gt; res;
  
          TryCatch tryCatch;
          script = Script::Compile(strExpr);
          res = script-&gt;Run();
  
          if (tryCatch.HasCaught()) {
              res = tryCatch.Message()-&gt;Get();
          }
  
          args.GetReturnValue().Set(res);
      }
      isolate-&gt;Dispose();
  
  }
  
  
  void TestContext2(const FunctionCallbackInfo&lt;Value&gt;&amp; args) {
  
      Isolate *isolate = args.GetIsolate();
      Isolate::Scope isolate_scope(isolate);
      HandleScope handle_scope(isolate);
      Local&lt;Context&gt; context = Context::New(isolate);
      Context::Scope context_scope(context);
  
      Handle&lt;String&gt; strExpr = Handle&lt;String&gt;::Cast(args[0]);
      Handle&lt;Script&gt; script;
      Handle&lt;Value&gt; res;
  
      TryCatch tryCatch;
      script = Script::Compile(strExpr);
      res = script-&gt;Run();
  
      if (tryCatch.HasCaught()) {
          res = tryCatch.Message()-&gt;Get();
      }
  
      args.GetReturnValue().Set(res);
  }
  
  void Init(Handle&lt;Object&gt; exports, Handle&lt;Object&gt; module) {
      NODE_SET_METHOD(exports, "TestContext1", TestContext1);
      NODE_SET_METHOD(exports, "TestContext2", TestContext2);
  }
  
  NODE_MODULE(addon, Init)
  </code></pre>
  
  <p>And then testing it with js code:</p>
  
  <pre><code>var addon = require('addon.node')
  var i = 0;
  setInterval(function () {
      msg = addon.TestContext1("process.exit()"); // or msg = addon.TestContext2("process.exit()");
      console.log(msg, i++, process.memoryUsage().heapUsed/1024/1024);
  }, 2);
  </code></pre>
  
  <p>Every function have different problems:</p>
  
  <p><strong>TestContext1</strong> works fine but accessing global context and shutting down process.</p>
  
  <p><strong>TestContext2</strong> does not have access to global context but gives memory leaks.</p>
  
  <p>All what I need - execute js script in isolated context without memory leaks.</p>
  
  <p>node vm doesn't work because vm.runInNewContext() have same memory leaks. </p>
  
  <p>Does anybody have some ideas?</p>