Alex Rivera | Logout

What are your strategies to keep the memory usage low?

Asked 2008-09-27T21:41:33.183
30

Ruby is truly memory-hungry - but also worth every single bit.

What do you do to keep the memory usage low? Do you avoid big strings and use smaller arrays/hashes instead or is it no problem to concern about for you and let the garbage collector do the job?

Edit: I found a nice article about this topic here - old but still interesting.

Edit
Report

3 Answers

9

I've found Phusion's Ruby Enterprise Edition (a fork of mainline Ruby with much-improved garbage collection) to make a dramatic difference in memory usage... Plus, they've made it extraordinarily easy to install (and to remove, if you find the need).

You can find out more and download it on their website.

answered 2008-09-28T03:17:01.923
6
  1. Choose date structures that are efficient representations, scale well, and do what you need.
  2. Use algorithms that work using efficient data structures rather than bloated, but easier ones.
  3. Look else where. Ruby has a C bridge and its much easier to be memory conscious in C than in Ruby.
answered 2008-09-28T13:00:10.337
3

I am not a ruby developer but I think some techniques and methods are true of any language:

Use the minimum size variable suitable for the job
Destroy and close variables and connections when not in use
However if you have an object you will need to use many times consider keeping it in scope Any loops with manipulations of a big string dp the work on a smaller string and then append to bigger string

Use decent (try catch finally) error handling to make sure objects and connections are closed

When dealing with data sets only return the minimum necessary

answered 2008-09-27T21:56:15.610

Your Answer