You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit dcaf058
Browse filesBrowse the repository at this point in the historyBrowse files
fix(runtime): release owned instance-method returns that hit a cached wrapper (#569)
Caches::Instances holds one retain per wrapped native object, so a result
the caller owns (+1) that already has a JS wrapper carries a surplus
reference. Interop::GetResult released it only for class methods and C
functions. For instance methods the object leaked one retain per call:
immutable.copy(), and X.alloc().init...() whenever the object got wrapped
during the initializer (a JS initializer, or a native one calling a JS
method on it), which meant those objects were never freed.
Instance methods had been left out because JS implementations handed
their results to native code at +0, so an owned return carried no real
+1. That was a bug of its own: a native caller of a JS copyWithZone:,
mutableCopyWithZone:, new-family method or owned-return getter released
an object it did not own.
- JS implementations hand owned results to native callers at +1
(ArgConverter::RetainOwnedResult): always for the copy, mutableCopy and
new families and metadata-flagged owned returns, and for initializers
and -awakeAfterUsingCoder: when the result is not the receiver. The
classification comes from the method's metadata, or from the selector's
method family where there is none, and is stored on the
MethodCallbackWrapper. JS property getters take the same path.
- Interop::ReleasesCachedOwnedReturn is the one rule for dropping a
surplus +1, used by GetResult and ConstructObject: release unless the
call consumed a receiver that existed before it. An initializer on a
receiver allocated for the call releases whatever it answers, which is
only balanced because JS initializers retain a non-receiver result.
- -unarchiver:didDecodeObject: consumes its object argument and returns
retained (Interop::ConsumesArgument, ReturnsRetained). A JS
implementation that answers the argument is neither retained nor
released; one that answers anything else has its result retained and
the argument released, also on MethodCallback's early returns. A call
from JS to a native implementation retains the argument it passes.
- Owned results that JS receives as primitives (string, number, date,
boolean, null) and owned block results release their +1 once the
runtime holds what it keeps. For a JS function's own block that release
can be the last reference and run the dispose helper inline.
- ArgConverter::SetValue reports whether it wrote an object the caller
does not own. Inferring that from the JS value afterwards retained a
new DictionaryAdapter a second time, because the adapter attaches a
wrapper to the object it adapts.
- ConstructObject reads the cached handle before releasing: the release
can be an adapter's last reference, which resets the handle.
JS implementations of owned-return methods now return +1 to native
callers, as ARC callers always assumed. A caller that ignores the method
family (performSelector:, KVC) on a JS method exposed under a copy,
mutableCopy or new name leaks one retain per call, as it does for a
native method with such a name.
Fixes#566
0 commit comments