Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ruby garbage collect

When would you use this garbage collection method in your Ruby program(s)?

GC.start 
like image 652
keruilin Avatar asked May 20 '11 03:05

keruilin


People also ask

How does generational garbage collection work?

The Generational Garbage Collection ProcessFirst, any new objects are allocated to the eden space. Both survivor spaces start out empty. When the eden space fills up, a minor garbage collection is triggered. Referenced objects are moved to the first survivor space.

How does rust garbage collect?

Rust is a general-purpose programming language that is both type- and memory-safe. Rust does not use a garbage collector, but rather achieves these properties through a sophisticated, but complex, type system. Doing so makes Rust very efficient, but makes Rust relatively hard to learn and use.

How does Ruby manage memory?

For Dynamic Memory allocation, the Ruby program uses Heap memory and the basic unit of the heap is a slot. Here, each slot occupies a value which is known as RVALUE. This RVALUE comprises 40 bytes and a container for objects of all types (Array, String, Class).

Does OCaml have garbage collection?

Garbage collection, reference counting, explicit allocation. As with all modern languages, OCaml provides a garbage collector so that you don't need to explicitly allocate and free memory as in C/C++.


1 Answers

There are occasions when it's necessary to kick it off, but usually it works fine by itself. I've had situations where an app will chew through 1GB of memory if left unchecked, pushing deep into swap, where triggering GC.start intermittently will cut that to 100MB.

The trouble is that calling this method is very expensive and can slow down your application considerably if used aggressively.

like image 92
tadman Avatar answered Sep 22 '22 22:09

tadman