sorry for my missed english.
this is "indirect" response to your question.
you can set to null objects at "script side", to make garbage collected.
24 Ekim 2013 Perşembe 06:25:10 UTC+3 tarihinde Yorath Wang yazdı:
>
> I am using v8 (tag 3.22.19) built as shared library, the environment is
> windows 8.1 x64, visual studio 2010.
> I use External::new(ptr) to pass the pointer to Print function, but the
> ptr is allocated use new, I don't know how to free the memory.
> Then i came across the API SetWeak, but there is no document at all. I try
> to use it with the codes below, but the WeakPtrCallback is never called,
> which leads to the memory leak.
> Anyone knows how to deal with this problem? Thanks!
>
> #include <v8.h>
> #include <vld.h>
> #include <memory>
>
> void Print(const v8::FunctionCallbackInfo<v8::Value>& data) {
>
> }
>
> void WeakPtrCallback(
> const v8::WeakCallbackData<v8::Object, std::weak_ptr<int>>& data) {
> delete data.GetParameter();
> }
>
> int main() {
> auto isolate = v8::Isolate::GetCurrent();
> v8::HandleScope handle_scope(isolate);
> auto context = v8::Context::New(isolate);
>
> auto ptr = std::shared_ptr<int>(new int(3));
> auto data = new std::weak_ptr<int>(ptr);
>
> auto global = context->Global();
> auto func_tpl = v8::FunctionTemplate::New(Print,
> v8::External::New(data));
>
> context->Enter();
>
> auto func = func_tpl->GetFunction();
> global->Set(v8::String::New("print"), func);
> auto obj = v8::Persistent<v8::Object>(isolate, global);
> obj.SetWeak<std::weak_ptr<int>>(data, WeakPtrCallback);
>
> context->Exit();
> obj.Reset();
>
> return 0;
> }
>
>
--
--
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.