>From v8/include.h:
/**
* Install a finalization callback on this object.
* NOTE: There is no guarantee as to *when* or even *if* the callback is
* invoked. The invocation is performed solely on a best effort basis.
* As always, GC-based finalization should *not* be relied upon for any
* critical form of resource management!
*/
template<typename P>
V8_INLINE void SetWeak(
P* parameter,
typename WeakCallbackData<T, P>::Callback callback);
On 23 December 2014 at 10:53, Tom Fan <[email protected]> wrote:
> The NewType::~NewType is not called, the test code as follow.
>
> #include "v8.h"
>
> #include "libplatform/libplatform.h"
>
>
>
> class NewType
>
> {
>
> public:
>
> static void WeakPtrCallback(const v8::WeakCallbackData<v8::Object,
> NewType>& data)
> {
>
> delete data.GetParameter();
>
> }
>
> NewType(v8::Isolate *isolate, v8::Handle<v8::Object> handle):
> isolate_(isolate)
> {
>
> printf("%s\n", __PRETTY_FUNCTION__);
>
> handle_.Reset(isolate, handle);
>
> handle_.SetWeak(this, WeakPtrCallback);
>
> }
>
> ~NewType()
>
> {
>
> handle_.Reset();
>
> printf("%s\n", __PRETTY_FUNCTION__);
>
> }
>
> private:
>
> v8::Persistent<v8::Object> handle_;
>
> v8::Isolate *isolate_;
>
>
>
> };
>
>
>
> int main(int argc, char *argv[])
>
> {
>
> v8::Platform* platform = v8::platform::CreateDefaultPlatform();
>
> v8::V8::InitializePlatform(platform);
>
> v8::V8::Initialize();
>
> v8::V8::SetFlagsFromCommandLine(&argc, argv, true);
>
> v8::Isolate* isolate = v8::Isolate::New();
>
> {
>
> v8::Isolate::Scope isolate_scope(isolate);
>
> v8::HandleScope handle_scope(isolate);
>
> v8::Local<v8::Context> context = v8::Context::New(isolate);
>
> v8::Context::Scope context_scope(context);
>
> v8::Local<v8::ObjectTemplate> tpl =
> v8::ObjectTemplate::New(isolate);
>
> tpl->SetInternalFieldCount(1);
>
> v8::Local<v8::Object> value = tpl->NewInstance();
>
> new NewType(isolate, value);
>
> context->Global()->Set(v8::String::NewFromUtf8(isolate, "test"),
> value);
> }
>
>
> isolate->RequestGarbageCollectionForTesting(v8::Isolate::kFullGarbageCollection);
>
> isolate->Dispose();
>
> v8::V8::Dispose();
>
> v8::V8::ShutdownPlatform();
>
> delete platform;
>
> }
>
>
> --
> --
> 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.
>
--
--
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.