Nix 2.17.0
Nix, the purely functional package manager; stable external interfaces
|
Reference counting and garbage collector operations. More...
Functions | |
nix_err | nix_gc_incref (nix_c_context *context, const void *object) |
Increase the GC refcount. More... | |
nix_err | nix_gc_decref (nix_c_context *context, const void *object) |
Decrease the GC refcount. More... | |
void | nix_gc_now () |
Trigger the garbage collector manually. More... | |
void | nix_gc_register_finalizer (void *obj, void *cd, void(*finalizer)(void *obj, void *cd)) |
Register a callback that gets called when the object is garbage collected. More... | |
Reference counting and garbage collector operations.
Nix's evaluator uses a garbage collector. To ease C interop, we implement a reference counting scheme, where objects will be deallocated when there are no references from the Nix side, and the reference count kept by the C API reaches 0
.
Functions returning a garbage-collected object will automatically increase the refcount for you. You should make sure to call nix_gc_decref
when you're done.
nix_err nix_gc_decref | ( | nix_c_context * | context, |
const void * | object | ||
) |
Decrease the GC refcount.
[out] | context | Optional, stores error information |
[in] | object | The object to stop referencing |
nix_err nix_gc_incref | ( | nix_c_context * | context, |
const void * | object | ||
) |
Increase the GC refcount.
The nix C api keeps alive objects by refcounting. When you're done with a refcounted pointer, call nix_gc_decref.
[out] | context | Optional, stores error information |
[in] | object | The object to keep alive |
void nix_gc_now | ( | ) |
Trigger the garbage collector manually.
You should not need to do this, but it can be useful for debugging.
void nix_gc_register_finalizer | ( | void * | obj, |
void * | cd, | ||
void(*)(void *obj, void *cd) | finalizer | ||
) |
Register a callback that gets called when the object is garbage collected.
[in] | obj | the object to watch |
[in] | cd | the data to pass to the finalizer |
[in] | finalizer | the callback function, called with obj and cd |