Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions NativeScript/runtime/LeakProbe.mm
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ void ForEachCanaryStateHandle(Isolate* isolate, void* context,
}

void DrainReleases(Isolate* isolate) {
ObjectManager::RunDeferredReleases(isolate);
WrapperLifetime::DrainReleases(isolate);
WrapperLifetimeCanary::ReleaseDeadStates(isolate);
}
Expand Down
5 changes: 3 additions & 2 deletions NativeScript/runtime/LeakProbeSPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,9 @@ struct Host {
// Any thread.
void (*destroyPoster)(Poster* poster);

// Releases the native objects wrapper lifetime modes queued for release,
// and lets go of the canary states of deallocated objects. Can run JS.
// Releases the native objects wrapper lifetime modes queued for release and
// those a collection or explicit release on another thread left for this
// one, and lets go of the canary states of deallocated objects. Can run JS.
void (*drainReleases)(v8::Isolate* isolate);
const char* (*lifetimeMode)();
const char* (*lifetimeScope)();
Expand Down
4 changes: 4 additions & 0 deletions NativeScript/runtime/ObjectManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,10 @@ class ObjectManager {
// release over as its own retain instead of retaining again; returns whether
// it did. Once the entry holds its reference, call ProtectIfNativelyRetained.
static bool TakeDeferredRelease(v8::Isolate* isolate, id obj);
// Makes the releases waiting for the runtime's thread now, rather than from
// the event loop task posted for them. Only where JS may run: a release can
// reach a JS-implemented -dealloc. Off the runtime's thread, does nothing.
static void RunDeferredReleases(v8::Isolate* isolate);
// A class that tracks native retains (ClassBuilder::TracksNativeRetains)
// protects its wrapper when native code first retains the object past the
// runtime's own retain. A native retain made while a release waited found no
Expand Down
9 changes: 9 additions & 0 deletions NativeScript/runtime/ObjectManager.mm
Original file line number Diff line number Diff line change
Expand Up @@ -573,6 +573,15 @@ void DisposeHandle(v8::Isolate* isolate,
return true;
}

void ObjectManager::RunDeferredReleases(Isolate* isolate) {
if (!OnRuntimeThreadOf(isolate)) {
return;
}
if (DeferredReleases* pending = Caches::ExistingStateFor<DeferredReleases>(isolate)) {
DrainDeferredReleases(pending);
}
}

void ObjectManager::ProtectIfNativelyRetained(Isolate* isolate, id obj, ObjCDataWrapper* wrapper) {
// Only a wrapper the class's -release unprotects again may be protected.
if (ClassBuilder::TracksNativeRetains(isolate, object_getClass(obj)) && [obj retainCount] > 1) {
Expand Down
4 changes: 3 additions & 1 deletion NativeScriptLeakProbe/NativeScriptLeakProbe.mm
Original file line number Diff line number Diff line change
Expand Up @@ -1596,7 +1596,9 @@ bool FindCycle(Isolate* isolate, const HeapGraphNode* start,
constexpr int kSettleCollections = 3;

// Until drained, a dead wrapper's queued retain reads as an owner of its
// object, and a deallocated object's canary state as a root. Runs JS.
// object, a deallocated object's canary state as a root, and an object whose
// release waits for this thread has no wrapper, so what it owns looks owned
// from outside. Runs JS.
void Settle(Isolate* isolate) {
for (int i = 0; i < kSettleCollections; i++) {
isolate->LowMemoryNotification();
Expand Down
Loading
Loading