module GC

Defined in:

gc.cr
gc/boehm.cr
gc/none.cr

Class Method Summary

Class Method Detail

def self.collect : Nil #

Collect the HEAP memory now, instead of waiting until the HEAP is full.


def self.disable : Nil #

Disables GC collections. The GC will always increase the HEAP size when the HEAP is full. Call GC.enable as many times as GC.disable was called to reenable GC collections.


def self.enable : Nil #

Enables GC collections. This is the default behavior. The GC will collect memory when the HEAP is full. Must be called as many times as GC.disable was called.


def self.malloc(size : Int) : Pointer(Void) #

Allocates and clears size bytes of memory.

The resulting object may contain pointers and they will be tracked by the GC.

The memory will be automatically deallocated when unreferenced.

If the memory can't be allocated (out of memory), the program aborts with an error message written to the standard error.


def self.malloc_atomic(size : Int) : Pointer(Void) #

Allocates size bytes of pointer-free memory.

The client promises that the resulting object will never contain any pointers.

The memory is not cleared. It will be automatically deallocated when unreferenced.

If the memory can't be allocated (out of memory), the program aborts with an error message written to the standard error.


def self.prof_stats #

Returns extended profiling statistics about the HEAP memory and GC collections.


def self.realloc(pointer : Pointer(T), size : Int) : Pointer(T) forall T #

Changes the allocated memory size of pointer to size. If this can't be done in place, it allocates size bytes of memory and copies the content of pointer to the new location.

If pointer was allocated with .malloc_atomic, the same constraints apply.

The return value is a pointer that may be identical to pointer or different.

If the memory can't be allocated (out of memory), the program aborts with an error message written to the standard error.

WARNING Memory allocated using Pointer.malloc must be reallocated using Pointer#realloc instead.


def self.stats : GC::Stats #

Returns statistics about the current HEAP memory.