Thanks for the reply Loïc
On Saturday, 15 August 2015 21:48:11 UTC+1, Loïc PORTALES wrote: > > > Hello, > > Yes, while your handles are in an handle scope they will not be deleted. > So in your case you do not need to use a persistent handle. > > You must use a persistent handle only in case you want to keep an object > which is no longer in a handle context. For example, if you got the handle > on a callback function from the main thread then you use it from an other > thread, you must use a persistent handle, to make sure it will not be > deleted while there is no handle context holding it. > > About the persistent handle, be careful to release it : > http://izs.me/v8-docs/classv8_1_1Persistent.html#a33e53191844272ba0f2da4f55fc12297 > > Loïc > > > Le vendredi 14 août 2015 21:33:24 UTC+8, Andy C a écrit : >> >> Maybe it is not as bad as I thought. I missed a bit of a sentence in the >> V8 embedder's guide: >> >> When the destructor, HandleScope::~HandleScope, is called the handle >>> scope is deleted. Objects referred to by handles within the deleted handle >>> scope are eligible for removal in the next garbage collection *if there >>> are no other references to them*. >> >> >> I *think* this means that because fs.writeFile() has a reference to the >> Buffer, it will not be garbage collected, and the memory held on to. >> >> Andy >> >> >> On Thursday, 13 August 2015 23:09:39 UTC+1, Andy C wrote: >>> >>> Hi, >>> I am writing a C++ module for node. I have a JS callback registered >>> which will receive regular callbacks with binary data (audio data). >>> >>> My C++ to call the callback looks a bit like: >>> >>> UniquePersistent<v8::Function> dataCallback = // from somewhere... >>> >>> HandleScope scope(isolate); >>> >>> const unsigned argc = 1; >>> auto buffer = node::Buffer::New(dataSize); >>> std::memcpy(node::Buffer::Data(buffer), data.get(), dataSize); >>> >>> Local<Value> argv[argc] = { buffer }; >>> >>> auto fn = Local<Function>::New(isolate, dataCallback); >>> auto context = isolate->GetCurrentContext(); >>> auto global = context->Global(); >>> fn->Call(global, argc, argv); >>> >>> At the moment my callback is simply passing the buffer on to >>> fs.writeFile(...): >>> >>> var fs = require('fs'); >>> mymodule.dosomething(function(data) { >>> fs.writeFile('raw_data', data, { flag: 'a' }) >>> }); >>> >>> This appears to work, however the lifetime of the buffer object is >>> suspect. This seems unsafe, as my understanding is that the Local<Buffer> >>> is going to be cleared up when the HandleScope is destroyed after the >>> callback has returned. Unfortunately, fs.writeFile() is probably still busy >>> with the buffer. >>> >>> The key would seem to be something to do with Persistent<> and >>> UniquePersistent<> but I don't quite grok it. >>> >>> Any tips, or pointers to examples would be great... >>> >>> >>> -- Job board: http://jobs.nodejs.org/ New group rules: https://gist.github.com/othiym23/9886289#file-moderation-policy-md Old group rules: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines --- You received this message because you are subscribed to the Google Groups "nodejs" group. To unsubscribe from this group and stop receiving emails from it, send an email to nodejs+unsubscr...@googlegroups.com. To post to this group, send email to nodejs@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/nodejs/3c0741ee-afe3-4225-93c1-4b185f07a267%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.