Crate boehm_gc [] [src]

boehm_gc is an allocator crate that provides an interface to the Boehm conservative garbage collector. The allocator that this crate provides ensures that all objects that it allocates will root any GC'd pointers that the objects may contain. GC'd pointers are allocated using the gc_allocate function and are freed automatically as they become unreachable.

This crate can only be used with recent Rust nightlies due to the allocator feature being brand new.



Used as an argument to register_finalizer to influence the circumstances upon which the garbage collector will run finalizers.



This implementation of __rust_allocate invokes GC_malloc_uncollectable, which allocates memory that is not collectable by the garbage collector but is capable of rooting GC'd pointers. Any pointer that resides in memory allocated by Rust's allocator will be traced for pointers, and any pointers that are contained within this memory are considered to be rooted.


Deallocates memory allocated by GC_malloc_uncollectable. This memory isn't normally collectable so we rely on Rust's drop glue to free the memory that it's allocated. Luckily, it's really good at that sort of thing!


Returns the number of bytes allocated since the last GC.


Returns a lower bound on the number of free bytes in the heap.


Allocates size bytes on the managed heap and returns a pointer to the newly-allocated memory. This memory is tracked by the garbage collector and will be freed automatically when it is no longer reachable.


Forces the garbage collector to run, deallocating any unreachable memory. This is a full, stop-the-world collection.


Disables the garbage collector and prevents gc_collect() from doing anything.


Enables the garbage collector, if the number of times that gc_enable() has been called is the same as the number of times that gc_disable() has been called.


Returns the number of bytes in the managed heap, including empty blocks and fragmentation loss.


Attaches a finalizer function and metadata object to a garbage-collected pointer. The finalizer function will be run right before an object is collected, after it has become unreachable. The first argument to the finalizer function will be the object being collected (the ptr argument), while the second argument to the finalizer function will be the metadata object passed as the data argument.


Sets the function that the GC calls when all available memory is exhausted. For now, this function must not return. The Boehm GC /does/ allow the function to return, but it must return either null or a previously-allocated heap object.


Returns the total number of bytes allocated in this process.