当我尝试使持久句柄变弱时,为什么不调用WeakReference回调?请参阅以下示例:
void myWeakReferenceCallback(v8::Persistent<v8::Value> theValue, void *theParameter)
{
fprintf(stdout, "myWeakReferenceCallback");
}
void testWeakReferenceCallback()
{
v8::Persistent<v8::Value> persistent_value;
{
v8::Persistent<v8::Context> context = v8::Context::New();
v8::Context::Scope context_scope(context);
v8::HandleScope handle_scope;
v8::Local<v8::Value> local_value = v8::NumberObject::New(5.0);
persistent_value = v8::Persistent<v8::Value>::New(local_value);
persistent_value.MakeWeak(NULL, myWeakReferenceCallback);
context.Dispose();
}
persistent_value.Dispose();
}
答案 0 :(得分:0)
我相信有两个问题:
试试这个:
void myWeakReferenceCallback(v8::Persistent<v8::Value> theValue, void *theParameter)
{
fprintf(stdout, "myWeakReferenceCallback");
theValue.Dispose();
}
void testWeakReferenceCallback()
{
v8::Persistent<v8::Value> persistent_value;
{
v8::Persistent<v8::Context> context = v8::Context::New();
v8::Context::Scope context_scope(context);
v8::HandleScope handle_scope;
v8::Local<v8::Value> local_value = v8::NumberObject::New(5.0);
persistent_value = v8::Persistent<v8::Value>::New(local_value);
persistent_value.MakeWeak(NULL, myWeakReferenceCallback);
context.Dispose();
}
//persistent_value.Dispose();
while (!v8::V8::IdleNotification()); // force GC
}