Skip to main content

GC_register_finalizer

Function GC_register_finalizer 

Source
pub unsafe extern "C" fn GC_register_finalizer(
    arg1: *mut c_void,
    arg2: GC_finalization_proc,
    arg3: *mut c_void,
    arg4: *mut GC_finalization_proc,
    arg5: *mut *mut c_void,
)
Expand description

When obj is no longer accessible, invoke (*fn)(obj, cd). If a and b are inaccessible, and a points to b (after disappearing links have been made to disappear), then only a will be finalized. (If this does not create any new pointers to b, then b will be finalized after the next collection.) Any finalizable object that is reachable from itself by following one or more pointers will not be finalized (or collected). Thus cycles involving finalizable objects should be avoided, or broken by disappearing links. All but the last finalizer registered for an object is ignored. No-op in the find-leak mode. Finalization may be removed by passing 0 as fn. Finalizers are implicitly unregistered when they are enqueued for finalization (i.e. become ready to be finalized). The old finalizer and client data are stored in *ofn and *ocd, respectively. (ofn and/or ocd may be NULL. The allocator lock is held while *ofn and *ocd are updated. In case of error (no memory to register new finalizer), *ofn and *ocd remain unchanged.) fn is never invoked on an accessible object, provided hidden pointers are converted to real pointers only if the allocator lock is held, at least in the reader mode, and such conversions are not performed by finalization routines. If GC_register_finalizer() is aborted as a result of a signal, then the object may be left with no finalization, even if neither the old nor new finalizer were NULL. obj should be the starting address of an object allocated by GC_malloc or friends. obj may also be NULL or point to something outside the collector heap (in this case, fn is ignored, *ofn and *ocd are set to NULL). Note that any garbage collectible object referenced by cd will be considered accessible until the finalizer is invoked.