Module: GC

Defined in:
gc.c

Overview

The GC module provides an interface to Ruby’s mark and sweep garbage collection mechanism. Some of the underlying methods are also available via the ObjectSpace module.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.disableBoolean

Disables garbage collection, returning true if garbage collection was already disabled.

GC.disable   #=> false
GC.disable   #=> true

Returns:

  • (Boolean)


243
244
245
246
247
248
249
250
# File 'gc.c', line 243

VALUE
rb_gc_disable()
{
    int old = dont_gc;

    dont_gc = Qtrue;
    return old;
}

.enableBoolean

Enables garbage collection, returning true if garbage collection was previously disabled.

GC.disable   #=> false
GC.enable    #=> true
GC.enable    #=> false

Returns:

  • (Boolean)


222
223
224
225
226
227
228
229
# File 'gc.c', line 222

VALUE
rb_gc_enable()
{
    int old = dont_gc;

    dont_gc = Qfalse;
    return old;
}

.startnil .garbage_collectnil .garbage_collectnil

Initiates garbage collection, unless manually disabled.

Overloads:

  • .startnil

    Returns:

    • (nil)
  • .garbage_collectnil

    Returns:

    • (nil)
  • .garbage_collectnil

    Returns:

    • (nil)


1458
1459
1460
1461
1462
1463
# File 'gc.c', line 1458

VALUE
rb_gc_start()
{
    rb_gc();
    return Qnil;
}

.stressBoolean

returns current status of GC stress mode.

Returns:

  • (Boolean)


101
102
103
# File 'gc.c', line 101

static VALUE
gc_stress_get(self)
VALUE self;

.stress=(bool) ⇒ Boolean

updates GC stress mode.

When GC.stress = true, GC is invoked for all GC opportunity: all memory and object allocation.

Since it makes Ruby very slow, it is only for debugging.

Returns:

  • (Boolean)


120
121
122
# File 'gc.c', line 120

static VALUE
gc_stress_set(self, bool)
VALUE self, bool;

Instance Method Details

#startnil #garbage_collectnil #garbage_collectnil

Initiates garbage collection, unless manually disabled.

Overloads:

  • #startnil

    Returns:

    • (nil)
  • #garbage_collectnil

    Returns:

    • (nil)
  • #garbage_collectnil

    Returns:

    • (nil)


1458
1459
1460
1461
1462
1463
# File 'gc.c', line 1458

VALUE
rb_gc_start()
{
    rb_gc();
    return Qnil;
}