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 ofwaiting until the HEAP is full.


def self.disable : Nil #

Disables GC collections. The GCwill always increase the HEAP sizewhen the HEAP is full. CallGC.enable as many times asGC.disablewas called to reenable GC collections.


def self.enable : Nil #

Enables GC collections. This is the default behavior. The GCwill collect memorywhen the HEAP is full. Must be called as many times asGC.disable was called.


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

Allocates and clearssize bytes of memory.

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

The memorywill be automatically deallocatedwhen unreferenced.

If the memory can't be allocated (out of memory), the program abortswith an error messagewritten to the standard error.


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

Allocatessize bytes of pointer-free memory.

The client promises that the resulting objectwill never contain any pointers.

The memory is not cleared. Itwill be automatically deallocatedwhen unreferenced.

If the memory can't be allocated (out of memory), the program abortswith an error messagewritten 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 ofpointer tosize. If this can't be done in place, it allocatessize bytes of memory and copies the content ofpointer to the new location.

Ifpointerwas allocatedwith.malloc_atomic, the same constraints apply.

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

If the memory can't be allocated (out of memory), the program abortswith an error messagewritten to the standard error.

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


def self.stats : GC::Stats #

Returns statistics about the current HEAP memory.