Ruby Garbage Collection Deep Dive: Generational Garbage Collection | Jemma Issroff

03-Mar-2021 1122
This is the third post in the Ruby GC Deep Dive series. It’ll make most sense if you check out the previous two first:GC::INTERNAL_CONSTANTS lays out necessary definitions to understand the Ruby Object SpaceTri-Color Mark and Sweep explains the overall algorithm Ruby’s GC usesFor this post, we’ll learn about Generational GC. Generational garbage collection is predicated on the weak generational hypothesis: most objects die young. This means most objects will not have any active references, and so be available for collection soon after creation. The hypothesis also says that those objects which don’t die young tend to live for a long time. If they aren’t pretty immediately available for collection, they likely won’t be available for a while.We can look at a Rails example to justify this hypothesis to ourselves. To generate a webpage for a client request, the Rails application will create many new Ruby objects. Once the page has been returned to the client, all of these objects are no longer needed and their space in memory can be reclaimed. However, there are some objects which need to live between all requests, like controllers, configuration data, user sesssion data, and so on. These objects will live for a long, long time.
Use coupon code:

RUBYONRAILS

to get 30% discount on our bundle!
Prepare for your next tech interview with our comprehensive collection of programming interview guides. Covering JavaScript, Ruby on Rails, React, and Python, these highly-rated books offer thousands of essential questions and answers to boost your interview success. Buy our 'Ultimate Job Interview Preparation eBook Bundle' featuring 2200+ questions across multiple languages. Ultimate Job Interview Preparation eBook Bundle