All original content is created in Ukrainian. Not all content has been translated yet. Some posts may only be available in Ukrainian.Learn more

What is Garbage Collector in Ruby? How does it work and why do you need GC?

This content has been automatically translated from Ukrainian.
Garbage Collector in Ruby β€”, it is an automated memory management mechanism that is responsible for monitoring and releasing memory that is no longer used by the program. The GS makes it so that the memory that was allocated for objects that are no longer needed by the program can be reused, thereby optimizing the system's resources.
Just imagine that there are objects in memory that are unnecessary. Their number is constantly growing. Memory leak occurs. The server may stop responding, and in the case of scaling, your accounts will only increase. So GC is needed to use RAM efficiently.
Garbage Collector at Ruby works on the principle of "mark-and-sweep". The garbage collector passes through all objects that can be reached from root objects (for example, local variables and global variables) and labels (mark) them as "available". After the marking process is completed, the collector moves to the cleaning phase (sweep /sweeping), where it frees memory from all objects that were not marked. These objects are considered "unattainable" and their memory (the memory they previously occupied) can be reused.
Ruby also uses the concept of generations (Generational Garbage Collection or GGC), which includes dividing objects into generations according to their frequency of use, allowing more efficient memory management, focusing the garbage collector's efforts on younger, more dynamic objects that change more often.
GC is usually talked about when Memory Leak appears on the server. Of course, restarting the server will help for a while (RAM will clear and start filling up again), but it will still have to be dealt with.

This post doesn't have any additions from the author yet.

15 Apr 18:11

Π©ΠΎ Ρ‚Π°ΠΊΠ΅ HTTP Client hints (ΠŸΡ–Π΄ΠΊΠ°Π·ΠΊΠΈ ΠΊΠ»Ρ–Ρ”Π½Ρ‚Π°)?

meme code
meme code@memecode
18 Apr 05:27

Ѐіксимо ActiveRecord::ProtectedEnvironmentError Ρƒ Π»ΠΎΠΊΠ°Π»ΡŒΠ½ΠΎΠΌΡƒ сСрСдовищі

meme code
meme code@memecode
18 Apr 06:06

Π ΠΎΠ·Π±ΠΈΡ€Π°Ρ”ΠΌΠΎ ΠΏΠΎΠΌΠΈΠ»ΠΊΡƒ PG::ObjectInUse (Ruby on Rails)

meme code
meme code@memecode
27 Apr 09:29

What are CC and BCC in emails? What and how to use?

meme code
meme code@memecode
Π©ΠΎ Ρ‚Π°ΠΊΠ΅ ΠΏΡ€ΠΎΠΌΠΏΡ‚ (prompt) Ρ‚Π° ΠΏΡ€ΠΎΠΌΠΏΡ‚-Ρ–Π½ΠΆΠΈΠ½Ρ–Ρ€Ρ–Π½Π³?
03 May 12:08

Π©ΠΎ Ρ‚Π°ΠΊΠ΅ ΠΏΡ€ΠΎΠΌΠΏΡ‚ (prompt) Ρ‚Π° ΠΏΡ€ΠΎΠΌΠΏΡ‚-Ρ–Π½ΠΆΠΈΠ½Ρ–Ρ€Ρ–Π½Π³?

meme code
meme code@memecode
ZOMBIE in Ruby. What is it?
03 May 12:41

ZOMBIE in Ruby. What is it?

meme code
meme code@memecode
Π’Ρ€ΠΎΡ…ΠΈ ΠΏΡ€ΠΎ Ρ‚ΠΈΠΏΠΈ Ρ€Π΅Π°Π»Ρ–Π·Π°Ρ†Ρ–Ρ— Ruby (CRuby (MRI), JRuby, Rubinius, TruffleRuby, mruby)
05 May 12:36

Π’Ρ€ΠΎΡ…ΠΈ ΠΏΡ€ΠΎ Ρ‚ΠΈΠΏΠΈ Ρ€Π΅Π°Π»Ρ–Π·Π°Ρ†Ρ–Ρ— Ruby (CRuby (MRI), JRuby, Rubinius, TruffleRuby, mruby)

meme code
meme code@memecode
07 May 07:24

Π©ΠΎ Ρ‚Π°ΠΊΠ΅ Π½Π°Ρ‚ΠΈΠ²Π½ΠΈΠΉ машинний ΠΊΠΎΠ΄?

meme code
meme code@memecode
Π’ΠΌΠΈΠΊΠ°Ρ”ΠΌΠΎ YJIT Ρƒ Ruby 3.2.1 (Ruby on Rails)
08 May 07:57

Π’ΠΌΠΈΠΊΠ°Ρ”ΠΌΠΎ YJIT Ρƒ Ruby 3.2.1 (Ruby on Rails)

meme code
meme code@memecode
09 May 12:43

[Ѐікс] Rails Admin - undefined local variable or method javascript_importmap_shim_nonce_configuration_tag

meme code
meme code@memecode
Π©ΠΎ Ρ‚Π°ΠΊΠ΅ Ρ‚Π΅Ρ…Π½Ρ–Ρ‡Π½ΠΈΠΉ Π±ΠΎΡ€Π³ (technical debt) Π² IT ΠΏΡ€ΠΎΡ”ΠΊΡ‚Π°Ρ…?
13 May 06:17

Π©ΠΎ Ρ‚Π°ΠΊΠ΅ Ρ‚Π΅Ρ…Π½Ρ–Ρ‡Π½ΠΈΠΉ Π±ΠΎΡ€Π³ (technical debt) Π² IT ΠΏΡ€ΠΎΡ”ΠΊΡ‚Π°Ρ…?

meme code
meme code@memecode
13 May 07:11

What does scope mean in IT project management?

meme code
meme code@memecode