detach method Null safety
- Object detach
Detaches this finalizer from values attached with detach.
Each attachment between this finalizer and a value,
which was created by calling attach with the detach object as
detach
argument, is removed.
If the finalizer was attached multiple times to the same value with different detachment keys, only those attachments which used detach are removed.
After detaching, an attachment won't cause any callbacks to happen if the object become inaccessible.
Example:
final Finalizer<DBConnection> _finalizer = Finalizer((connection) {
connection.close();
});
class Database {
final DBConnection _connection;
final Finalizer<Connection> _finalizer;
Database._fromConnection(this._connection, this._finalizer);
// Some useful methods.
void close() {
// User requested close.
_connection.close();
// Detach from finalizer, no longer needed.
// Was attached using this object as `detach` token.
_finalizer.detach(this);
}
}
Implementation
void detach(Object detach);