[][src]Function dart_sys::Dart_NewWeakPersistentHandle

pub unsafe extern "C" fn Dart_NewWeakPersistentHandle(
    object: Dart_Handle,
    peer: *mut c_void,
    external_allocation_size: isize,
    callback: Dart_WeakPersistentHandleFinalizer
) -> Dart_WeakPersistentHandle

Allocates a weak persistent handle for an object.

This handle has the lifetime of the current isolate unless the object pointed to by the handle is garbage collected, in this case the VM automatically deletes the handle after invoking the callback associated with the handle. The handle can also be explicitly deallocated by calling Dart_DeleteWeakPersistentHandle.

If the object becomes unreachable the callback is invoked with the weak persistent handle and the peer as arguments. The callback is invoked on the thread that has entered the isolate at the time of garbage collection. This gives the embedder the ability to cleanup data associated with the object and clear out any cached references to the handle. All references to this handle after the callback will be invalid. It is illegal to call into the VM from the callback. If the handle is deleted before the object becomes unreachable, the callback is never invoked.

Requires there to be a current isolate.

\param object An object. \param peer A pointer to a native object or NULL. This value is provided to callback when it is invoked. \param external_allocation_size The number of externally allocated bytes for peer. Used to inform the garbage collector. \param callback A function pointer that will be invoked sometime after the object is garbage collected, unless the handle has been deleted. A valid callback needs to be specified it cannot be NULL.

\return The weak persistent handle or NULL. NULL is returned in case of bad parameters.