Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9216717
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T02:28:35+00:00 2026-06-18T02:28:35+00:00

Does garbage collector in Ruby take into account the size as well as the

  • 0

Does garbage collector in Ruby take into account the size as well as the amount of objects? For optimization, I’m considering of replacing Class instances with either Structs or plain Hashes. I would like to understand which given classes will have have the greatest impact on garbage collection.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T02:28:37+00:00Added an answer on June 18, 2026 at 2:28 am

    The guy who said that you should benchmark it is right — GC is a complex issue and it’s hard to give a 100% correct answer.

    Also, it depends on the implementation being used. In JRuby, it’s the JVM doing the work. In MRI, it’s a mark-and-sweep GC.

    On the case of MRI, it works more or less like this: each time that the Ruby interpreter needs more memory, it runs the GC to try and free it. If there isn’t enough memory, it’ll allocate more. And the GC decides that an object is ok to be freed (“mark” it) when there aren’t references to it.

    The only advice I can give you is to avoid using lots of objects that can’t be garbage collected. For example, if you’re building an array of strings (their size isn’t important), you should see performance degradation much more rapidly than if you created a big string concatenating each of the smaller ones.

    This is because in the latter the GC can destroy the small strings after they’re used, while in the former the array is always maintaining a reference to each one of them.

    EDIT: Of course, this assumes that the cost of maintaining them in memory is bigger than the slowdown of dealing with the “big string”. In some cases, it’s better to have small strings and then concatenate they all — resulting in a single slow operation. Again, these are just examples without benchmarks, don’t take them very seriously.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How much does the garbage collector affect performance when working with lots of objects
So does implementing Dispose() on the managed objects where would improve Garbage Collector's performance
How does the garbage collector determine whether an object is garbage? Does it refer
What exactly does the Objective-C garbage collector collect? For example, if I'm writing a
See also these related resources: Does the .NET garbage collector perform predictive analysis of
does Boo have a garbage collector? what type?
Possible Duplicate: Java garbage collector - When does it collect? When people say that
How does a copying garbage collector avoid memory fragmentation? Also, what consequences for heap-space
I am new to GC and wondering what does garbage collector collect besides reference
I am developing a parallel garbage collector. It is a tri-marking collector that does

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.