Open
Description
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 | - | ✔ |
- Is this matrix correct?
- The
Finalizer
docs make a point of stressing how very unreliable it is. Why would one ever chooseFinalizer
overNativeFinalizer
? - 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 handycalloc
andcalloc.free
functions. Given thatNativeFinalizer
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 toNativeFinalizer
. Is this correct?