Skip to content

Finalizer vs. NativeFinalizer #52436

Open
@DanielSWolf

Description

@DanielSWolf

I'm having a hard time understanding the exact differences between Finalizer (docs) and NativeFinalizer (docs). Here's a feature matrix I created, based on the officials documentation and a bit of guesswork.

Finalizer NativeFinalizer
Guaranteed to be called -
Guaranteed to be called in a timely manner - - (edited)
Can be called during synchronous operation -
Guaranteed not to be called prematurely with variable still in scope - ✔ (edited)
Premature execution can be prevented through Finalizable -
Callback can be Dart function object -
Callback can be native function -
  1. Is this matrix correct?
  2. The Finalizer docs make a point of stressing how very unreliable it is. Why would one ever choose Finalizer over NativeFinalizer?
  3. Some native functionality may already be wrapped in Dart code, so the callback for freeing a native resource may be a Dart function. For instance, package:ffi offers handy calloc and calloc.free functions. Given that NativeFinalizer only supports native callback functions, it seems that there is no way to reliably have a non-native free function called -- unless I were to wrap the Dart function in a native function just to be able to pass it to NativeFinalizer. Is this correct?

Metadata

Metadata

Assignees

Labels

P3A lower priority bug or feature requestarea-documentationPrefer using 'type-documentation' and a specific area label.area-vmUse area-vm for VM related issues, including code coverage, and the AOT and JIT backends.library-ffitriagedIssue has been triaged by sub teamtype-questionA question about expected behavior or functionality

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions