On Tue, Apr 18, 2017 at 9:31 AM, Gautham B A <[email protected]> wrote: > Thank you Ben. > Yes, there's a try_catch.HasCaught() before running the script in order to > prevent the process from exiting. > Here's the code that will cause the script to run - > int SendUpdate(std::string value, std::string meta, > std::string doc_type) { > v8::Locker locker(GetIsolate()); > v8::Isolate::Scope isolate_scope(GetIsolate()); > v8::HandleScope handle_scope(GetIsolate()); > > v8::Local<v8::Context> context = > v8::Local<v8::Context>::New(GetIsolate(), context_); > v8::Context::Scope context_scope(context); > > v8::TryCatch try_catch(GetIsolate()); > > v8::Handle<v8::Value> args[2]; > if (doc_type.compare("json") == 0) { > args[0] = > v8::JSON::Parse(v8::String::NewFromUtf8(GetIsolate(), > value.c_str())); > } else { > args[0] = v8::String::NewFromUtf8(GetIsolate(), value.c_str()); > } > > args[1] = > v8::JSON::Parse(v8::String::NewFromUtf8(GetIsolate(), meta.c_str())); > > if (try_catch.HasCaught()) { > last_exception = ExceptionString(GetIsolate(), &try_catch); > LOG(logError) << "Last exception: " << last_exception << '\n'; > } > > v8::Local<v8::Function> on_doc_update = > v8::Local<v8::Function>::New(GetIsolate(), on_update_); > on_doc_update->Call(context->Global(), 2, args); > > if (try_catch.HasCaught()) { > LOG(logDebug) << "Exception message: " > << ExceptionString(GetIsolate(), &try_catch) << '\n'; > > return ON_UPDATE_CALL_FAIL; > } > > return SUCCESS; > } > > Is it possible to reclaim the memory without shutting the VM down?
Depends on what you mean by 'reclaim' and 'memory leak' - memory isn't reclaimed until the garbage collector deems it necessary. People often mistake that for a memory leak when it is in fact the garbage collector doing its work (or rather, doing as little work as it can get away with.) I don't see an actual memory leak in the code you posted but creating a new ObjectTemplate for every query isn't very efficient. If you don't use ObjectTemplate features, replace it with Object::New(). -- -- v8-users mailing list [email protected] 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 [email protected]. For more options, visit https://groups.google.com/d/optout.
