# Memory concerns wrt garbage collection etc

**URL:** <https://www.ruby-forum.com/t/memory-concerns-wrt-garbage-collection-etc/138882>\
**Category:** Ruby\
**Created:** [May 28, 2008, 4:53pm UTC](https://www.ruby-forum.com/t/memory-concerns-wrt-garbage-collection-etc/138882 "2008-05-28T16:53:29Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Srijayanth\_S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/e95f7d/32.png) [@Srijayanth\_S](https://www.ruby-forum.com/u/Srijayanth_S)\
**Post date:** [May 28, 2008, 4:53pm UTC](https://www.ruby-forum.com/t/memory-concerns-wrt-garbage-collection-etc/138882/1 "2008-05-28T16:53:29Z")

</div>

Hello,

I have a script which basically launches several threads, each of them  
parsing a web page from a different link using Hpricot. I am not sure  
how many threads get spawned, could be in the hundreds. The question I  
have is, assuming we have a simple scenario where:

doc=Hpricot.new(open(“[http://somewhere/](http://somewhere/)”))

# a bunch of processing

doc=Hpricot.new(open(“[http://somewhere.else/](http://somewhere.else/)”))

# some more processing here.

When does the memory from the first instance get released? As soon as  
no references point to that chunk of memory or right at the end of the  
scope of wherever that object was instantiated?

Can someone please tell me as I have to my script running for months  
perhaps and I don’t know if its going to sit there eating memory for  
no reason 🙂

Thank you,

Jayanth

---

<div class="post-metadata">

**Author:** ![Srijayanth\_S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/e95f7d/32.png) [@Srijayanth\_S](https://www.ruby-forum.com/u/Srijayanth_S)\
**Post date:** [October 23, 2008, 4:24pm UTC](https://www.ruby-forum.com/t/memory-concerns-wrt-garbage-collection-etc/138882/2 "2008-10-23T16:24:02Z")

</div>

> doc=Hpricot.new(open(“[http://somewhere/](http://somewhere/)”))
> 
> # a bunch of processing
> 
> doc=Hpricot.new(open(“[http://somewhere.else/](http://somewhere.else/)”))
> 
> # some more processing here.
> 
> When does the memory from the first instance get released? As soon as  
> no references point to that chunk of memory or right at the end of the  
> scope of wherever that object was instantiated?

Theoretically as soon as you redefine doc you’ll no longer have any  
references to it so it will be collected when the GC “kicks in” or when  
you call GC.start–whichever comes first.  
GL.  
-=R

---

<div class="post-metadata">

**Author:** ![Srijayanth\_S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/e95f7d/32.png) [@Srijayanth\_S](https://www.ruby-forum.com/u/Srijayanth_S)\
**Post date:** [October 24, 2008, 9:37am UTC](https://www.ruby-forum.com/t/memory-concerns-wrt-garbage-collection-etc/138882/3 "2008-10-24T09:37:19Z")

</div>

2008/5/28 Srijayanth S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> I have a script which basically launches several threads, each of them  
> parsing a web page from a different link using Hpricot. I am not sure  
> how many threads get spawned, could be in the hundreds.

I doubt the usefulness of this. Since Ruby uses green threads chances  
are that your overall throughput could be better if you limit the  
number of threads. This also has the effect of reducing the amount of  
memory needed at a point in time. I’d seriously question this design.  
If you have multiple cores in your system and want to take advantage  
of them using multiple processes might also be an option.

Kind regards

robert
