# Garbage Collection

**URL:** <https://rubytalk.org/t/garbage-collection/38826>\
**Category:** ruby-talk\
**Created:** [3 July 2007 20:19 UTC](https://rubytalk.org/t/garbage-collection/38826 "2007-07-03T20:19:24Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Brett\_Simmers](https://avatars.discourse-cdn.com/v4/letter/b/d2c977/32.png) [@Brett\_Simmers](https://rubytalk.org/u/Brett_Simmers)\
**Post date:** [3 July 2007 20:19 UTC](https://rubytalk.org/t/garbage-collection/38826/1 "2007-07-03T20:19:24Z")

</div>

I know that the garbage collector will start when more memory is needed, but will it also start after the program has been running for a long period of time? I have a daemon written in Ruby that's been running for about 8 days now, and its memory usage has increased by about 1MB per day. It's up to 39MB by now which isn't bad, but if this trend continues it could get ugly after a few weeks. What I don't know is if it's actually using all that memory or if it just hasn't run the GC yet because the usage is still fairly low. I'm sure it wouldn't be hard to test this by putting a few calls to GC.start in the code and restarting it, but I'd really like to avoid restarting it if possible. Does anyone know which conditions will trigger the GC other than malloc failing?

Brett

---

<div class="post-metadata">

**Author:** ![Jan\_Svitok](https://avatars.discourse-cdn.com/v4/letter/j/cab0a1/32.png) [@Jan\_Svitok](https://rubytalk.org/u/Jan_Svitok)\
**Post date:** [3 July 2007 21:48 UTC](https://rubytalk.org/t/garbage-collection/38826/2 "2007-07-03T21:48:45Z")

</div>

[http://redhanded.hobix.com/inspect/theFullyUpturnedBin.html](http://redhanded.hobix.com/inspect/theFullyUpturnedBin.html) is  
interesting reading. Other than that, make sure you don't have left  
references... there are tools to check it, on windows there's Ruby  
Memory Validator by softwareverify, and some opensource ones... IIRC  
Eric Hodel did something some time ago (mem\_inspect)

[http://www.softwareverify.com/ruby/customBuild/memtrack/index.html](http://www.softwareverify.com/ruby/customBuild/memtrack/index.html)

> **[Software Tools | Software Verify](http://www.softwareverify.com/products/)**
>
> Listing of all our software tools for each language and technology that we support.

> **···**
>
> On 7/3/07, Brett Simmers \<bsimmers@cmu.edu\> wrote:
> 
> > I know that the garbage collector will start when more memory is needed,  
> > but will it also start after the program has been running for a long  
> > period of time? I have a daemon written in Ruby that's been running for  
> > about 8 days now, and its memory usage has increased by about 1MB per  
> > day. It's up to 39MB by now which isn't bad, but if this trend  
> > continues it could get ugly after a few weeks. What I don't know is if  
> > it's actually using all that memory or if it just hasn't run the GC yet  
> > because the usage is still fairly low. I'm sure it wouldn't be hard to  
> > test this by putting a few calls to GC.start in the code and restarting  
> > it, but I'd really like to avoid restarting it if possible. Does anyone  
> > know which conditions will trigger the GC other than malloc failing?

---

<div class="post-metadata">

**Author:** ![Tim\_Hunter4](https://avatars.discourse-cdn.com/v4/letter/t/ea5d25/32.png) [@Tim\_Hunter4](https://rubytalk.org/u/Tim_Hunter4)\
**Post date:** [3 July 2007 21:49 UTC](https://rubytalk.org/t/garbage-collection/38826/3 "2007-07-03T21:49:50Z")

</div>

Brett Simmers wrote:

> I know that the garbage collector will start when more memory is needed, but will it also start after the program has been running for a long period of time? I have a daemon written in Ruby that's been running for about 8 days now, and its memory usage has increased by about 1MB per day. It's up to 39MB by now which isn't bad, but if this trend continues it could get ugly after a few weeks. What I don't know is if it's actually using all that memory or if it just hasn't run the GC yet because the usage is still fairly low. I'm sure it wouldn't be hard to test this by putting a few calls to GC.start in the code and restarting it, but I'd really like to avoid restarting it if possible. Does anyone know which conditions will trigger the GC other than malloc failing?  
> Brett

This article may help.

[http://whytheluckystiff.net/articles/theFullyUpturnedBin.html](http://whytheluckystiff.net/articles/theFullyUpturnedBin.html)

> **···**
>
> --  
> RMagick OS X Installer [[http://rubyforge.org/projects/rmagick/\](http://rubyforge.org/projects/rmagick/%5C)]  
> RMagick Hints & Tips [[http://rubyforge.org/forum/forum.php?forum\_id=1618\](http://rubyforge.org/forum/forum.php?forum_id=1618%5C)]  
> RMagick Installation FAQ [[http://rmagick.rubyforge.org/install-faq.html\](http://rmagick.rubyforge.org/install-faq.html%5C)]

---

<div class="post-metadata">

**Author:** ![Joel\_VanderWerf1](https://avatars.discourse-cdn.com/v4/letter/j/94ad74/32.png) [@Joel\_VanderWerf1](https://rubytalk.org/u/Joel_VanderWerf1)\
**Post date:** [3 July 2007 23:09 UTC](https://rubytalk.org/t/garbage-collection/38826/4 "2007-07-03T23:09:20Z")

</div>

Brett Simmers wrote:

> I know that the garbage collector will start when more memory is needed, but will it also start after the program has been running for a long period of time? I have a daemon written in Ruby that's been running for about 8 days now, and its memory usage has increased by about 1MB per day. It's up to 39MB by now which isn't bad, but if this trend continues it could get ugly after a few weeks. What I don't know is if it's actually using all that memory or if it just hasn't run the GC yet because the usage is still fairly low. I'm sure it wouldn't be hard to test this by putting a few calls to GC.start in the code and restarting it, but I'd really like to avoid restarting it if possible. Does anyone know which conditions will trigger the GC other than malloc failing?  
> Brett

What ruby version?

I have the same problem with 1.8.6, but not with 1.8.4.

I'm pretty sure GC will have run by now. The threshold starts out at around 8Mb (GC runs when the total requested allocation since the last GC exceeds the threshold).

(It's a good idea to have a DRb backdoor to a process like this, so that you can connect to it and issue commands, not just GC.start.)

> **···**
>
> --  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407

---

<div class="post-metadata">

**Author:** ![Brett\_Simmers](https://avatars.discourse-cdn.com/v4/letter/b/d2c977/32.png) [@Brett\_Simmers](https://rubytalk.org/u/Brett_Simmers)\
**Post date:** [4 July 2007 02:07 UTC](https://rubytalk.org/t/garbage-collection/38826/5 "2007-07-04T02:07:48Z")

</div>

Joel VanderWerf wrote:

> What ruby version?
> 
> I have the same problem with 1.8.6, but not with 1.8.4.
> 
> I'm pretty sure GC will have run by now. The threshold starts out at around 8Mb (GC runs when the total requested allocation since the last GC exceeds the threshold).
> 
> (It's a good idea to have a DRb backdoor to a process like this, so that you can connect to it and issue commands, not just GC.start.)

I think the server it's running on has 1.8.5. Thanks to everyone for the responses, those articles were definitely interesting. I did some quick calculations based on which objects I know are persisting and I think it's actually using about 900kb per day of ram so manually activating GC wouldn't help much. I redesigned the core of the app and the next version isn't going to have nearly as much state so that won't be a problem any more when I deploy it next week.
