Skip to content

Clarify detachKey behavior in Finalizers #2016

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 7, 2021
Merged
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
23 changes: 12 additions & 11 deletions accepted/future-releases/1847 - FinalizationRegistry/proposal.md
Original file line number Diff line number Diff line change
Expand Up @@ -195,10 +195,10 @@ abstract class Finalizer<T> {
/// for registrations which have been detached since they were attached.
void attach(Object value, T token, {Object? detachKey});

/// Detaches the finalizer from any objects that used [detachKey] when
/// attaching the finalizer to them.
/// Detaches this finalizer from any objects that used the identical [detachKey] when
/// attaching this finalizer to them.
///
/// If the finalizer was attached multiple times to the same object with different
/// If this finalizer was attached multiple times to the same object with different
/// detachment keys, only those attachments which used [detachKey] are
/// removed.
///
Expand Down Expand Up @@ -248,8 +248,8 @@ abstract class Finalizable {
factory Finalizable._() => throw UnsupportedError("");
}

typedef NativeFinalizer = Void Function(Pointer<Void>);
typedef NativeFinalizerPtr = Pointer<NativeFunction<NativeFinalizer>>
typedef NativeFinalizerSignature = Void Function(Pointer<Void> token);
typedef NativeFinalizerPtr = Pointer<NativeFunction<NativeFinalizerSignature>>;

/// A native finalizer which can be attached to Dart objects.
///
Expand Down Expand Up @@ -301,14 +301,15 @@ abstract class NativeFinalizer {
/// [externalSize] is an amount of native (non-Dart) memory owned by the
/// given [value]. This information is used to drive garbage collection
/// scheduling heuristics.
void attach(Finalizable value, Pointer<Void> token, {Object? detachKey, int externalSize}});
void attach(Finalizable value, Pointer<Void> token,
{Object? detachKey, int externalSize});

/// Detaches the finalizer from any objects that used [detachKey] when
/// attaching the finalizer to them.
/// Detaches this finalizer from any objects that used the identical
/// [detachKey] when attaching this finalizer to them.
///
/// If the finalizer was attached multiple times to the same object with different
/// detachment keys, only those attachments which used [detachKey] are
/// removed.
/// If this finalizer was attached multiple times to the same object with
/// different detachment keys, only those attachments which used [detachKey]
/// are removed.
///
/// After detaching, an attachment won't cause any callbacks to happen if the
/// object become inaccessible.
Expand Down