Not a Memory Leak but Stale Objects - clears with GC.start

I have a long running process.

When it gets busy the memory the task uses grows from
300-400MB to 1.2-1.8GB

So I thought I had a leak… but when I do a GC.start
(Garbage Collection start)
the memory usage (shown by ‘top’) drops back to normal.

As a temporary solution I have the GC.start run once a minute and then
I started thinking…

I see a lot of threads pointing out problems with Ruby memory management
and garbage collection, so might this solution be ok to continue to use?

There is only one main loop, the rest are periodic calls
to Proc objects.

I thought when a function returns any stale objects could be released.
(And in fact they are when I call GC.start, so something else is
causing GC not to start on it’s own)

I am running Debian linux and have

ruby 1.8.7 (2010-08-16 patchlevel 302) [i486-linux]

I know there are newer versions of ruby,
but don’t want to upgrade just yet…

just lazy I guess :slight_smile:

tom

You really should upgrade to ruby 1.9.3 . A lot of GC related issues
have been addressed there.

Da: “Tom M.” [email protected]
A: [email protected]
Cc:
Data: Thu, 5 Apr 2012 20:06:09 +0900
Oggetto: Not a Memory Leak but Stale Objects - clears with GC.start

On Thu, Apr 5, 2012 at 1:06 PM, Tom M. [email protected]
wrote:

I started thinking…

I see a lot of threads pointing out problems with Ruby memory management
and garbage collection, so might this solution be ok to continue to use?

Many of those threads here which deal with GC are caused by
misunderstanding of GC. I don’t see that Ruby’s GC has serious
problems in recent versions of Ruby.

There is only one main loop, the rest are periodic calls
to Proc objects.

Closures holding on to objects for longer than necessary?

I thought when a function returns any stale objects could be released.
(And in fact they are when I call GC.start, so something else is
causing GC not to start on it’s own)

I faintly remember that there once GC did not free all objects it
could free but don’t remember the details - not even the Ruby version.

I am running Debian linux and have

ruby 1.8.7 (2010-08-16 patchlevel 302) [i486-linux]

I know there are newer versions of ruby,
but don’t want to upgrade just yet…

just lazy I guess :slight_smile:

Yeah, you’re lazy. Bad boy! :slight_smile:

I’d go to 1.9.3 rather sooner than later because it’s also faster for
many applications and it has Oniguruma which I wouldn’t want to miss
any more.

Kind regards

robert

I don’t know which gems are you using, but some gems interfacing with
external libraries may exhibit this behavior.

For example, RMagick has a tendency to eat up memory (on 1.8.x, and I
think on 1.9.x too), because it only “notifies” Ruby about the
interface objects, taking up a few kilobytes per image - but not
ImageMagick’s image data, which can be huge. Since Ruby “thinks”
you’re only using a little memory, it doesn’t bother to fire up GC -
and in the meantime your script takes up a few gigs of RAM. (Calling
GC.start periodically is the recommended solution for this.)

– Matma R.