Index: src/isolate.cc |
diff --git a/src/isolate.cc b/src/isolate.cc |
index 38a26be1e29a70450d6d08460fbe0e7473b25244..d25c8a20200ac0d57df2a38105d56cfe50d91709 100644 |
--- a/src/isolate.cc |
+++ b/src/isolate.cc |
@@ -2030,6 +2030,47 @@ Isolate::ThreadDataTable::~ThreadDataTable() { |
// DCHECK_NULL(list_); |
} |
+void Isolate::ReleaseManagedObjects() { |
+ Isolate::ManagedObjectFinalizer* current = |
+ managed_object_finalizers_list_.next_; |
+ while (current != nullptr) { |
+ Isolate::ManagedObjectFinalizer* next = current->next_; |
+ current->Dispose(); |
+ delete current; |
+ current = next; |
+ } |
+} |
+ |
+Isolate::ManagedObjectFinalizer* Isolate::RegisterForReleaseAtTeardown( |
+ void* value, Isolate::ManagedObjectFinalizer::Deleter deleter) { |
+ DCHECK_NOT_NULL(value); |
+ DCHECK_NOT_NULL(deleter); |
+ |
+ Isolate::ManagedObjectFinalizer* ret = new Isolate::ManagedObjectFinalizer(); |
+ ret->value_ = value; |
+ ret->deleter_ = deleter; |
+ // Insert at head. We keep the head alive for the lifetime of the Isolate |
+ // because otherwise we can't reset the head, should we delete it before |
+ // the isolate expires |
+ Isolate::ManagedObjectFinalizer* next = managed_object_finalizers_list_.next_; |
+ managed_object_finalizers_list_.next_ = ret; |
+ ret->prev_ = &managed_object_finalizers_list_; |
+ ret->next_ = next; |
+ if (next != nullptr) next->prev_ = ret; |
+ return ret; |
+} |
+ |
+void Isolate::UnregisterFromReleaseAtTeardown( |
+ Isolate::ManagedObjectFinalizer** finalizer_ptr) { |
+ DCHECK_NOT_NULL(finalizer_ptr); |
+ Isolate::ManagedObjectFinalizer* finalizer = *finalizer_ptr; |
+ DCHECK_NOT_NULL(finalizer->prev_); |
+ |
+ finalizer->prev_->next_ = finalizer->next_; |
+ if (finalizer->next_ != nullptr) finalizer->next_->prev_ = finalizer->prev_; |
+ delete finalizer; |
+ *finalizer_ptr = nullptr; |
+} |
Isolate::PerIsolateThreadData::~PerIsolateThreadData() { |
#if defined(USE_SIMULATOR) |
@@ -2399,6 +2440,7 @@ void Isolate::Deinit() { |
root_index_map_ = NULL; |
ClearSerializerData(); |
+ ReleaseManagedObjects(); |
} |