I have tried to Google a lot about Rails Garbage collector, but I didn't get a reliable answer. Has anyone got a source to show how garbage collection is implemented in Rails? How can we control it?
Many modern programming languages manage memory for you, and Ruby is no different. Ruby manages memory usage using a garbage collector (also called gc).
Garbage collection (GC) is a memory recovery feature built into programming languages such as C# and Java. A GC-enabled programming language includes one or more garbage collectors (GC engines) that automatically free up memory space that has been allocated to objects no longer needed by the program.
Garbage collection in Java is the process by which Java programs perform automatic memory management. Java programs compile to bytecode that can be run on a Java Virtual Machine, or JVM for short. When Java programs run on the JVM, objects are created on the heap, which is a portion of memory dedicated to the program.
Rails is a framework, not a language. The language behind Rails is called Ruby.
This means there is no notion of Garbage Collector in Rails. You should search for documentation about the Ruby Garbage Collector.
You can start from the Ruby GC module. The GC module provides an interface to Ruby’s mark and sweep garbage collection mechanism.
Depending on the Ruby language version, the Garbage Collector may have a different behavior. The article How Ruby Manages Memory and Garbage Collection describes the Ruby 1.9 Garbage Collector. In Ruby 2.0 the GC has been improved and the implementation changed a bit.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With