From 7f48722d72a8f88b956828d643dc7c96b136d5f4 Mon Sep 17 00:00:00 2001 From: Georgy Angelov Date: Sun, 22 Mar 2015 10:05:49 +0000 Subject: [PATCH] Dispose of the persistent handles when they are GC'd by ruby --- ext/v8/init.cc | 2 -- ext/v8/ref.h | 11 ++++++++--- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/ext/v8/init.cc b/ext/v8/init.cc index 1e68a87..95c8a91 100644 --- a/ext/v8/init.cc +++ b/ext/v8/init.cc @@ -19,11 +19,9 @@ extern "C" { String::Init(); Locker::Init(); - // GC::Init(); // Accessor::Init(); // Invocation::Init(); // Signature::Init(); - // Object::Init(); // Array::Init(); // Function::Init(); // Date::Init(); diff --git a/ext/v8/ref.h b/ext/v8/ref.h index 28b77e4..311cb4d 100644 --- a/ext/v8/ref.h +++ b/ext/v8/ref.h @@ -49,7 +49,7 @@ namespace rr { return Qnil; } - return Data_Wrap_Struct(Class, 0, &Holder::enqueue, new Holder(handle)); + return Data_Wrap_Struct(Class, 0, &Holder::destroy, new Holder(handle)); } /* @@ -105,8 +105,13 @@ namespace rr { v8::Persistent* handle; bool disposed_p; - static void enqueue(Holder* holder) { - // TODO + static void destroy(Holder* holder) { + holder->dispose(); + + // TODO: This previously enqueued the holder to be disposed of + // in `AddGCPrologueCallback`. Now that `AddGCPrologueCallback` depends + // on an active Isolate (and must be registered for each one) it + // might be better to just dispose of the object on the spot. // GC::Finalize(holder); } };