# Memory management

**URL:** <https://www.ruby-forum.com/t/memory-management/117857>\
**Category:** Ruby\
**Created:** [October 21, 2007, 5:44pm UTC](https://www.ruby-forum.com/t/memory-management/117857 "2007-10-21T17:44:05Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Bazsl](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/ad7895/32.png) [@Bazsl](https://www.ruby-forum.com/u/Bazsl)\
**Post date:** [October 21, 2007, 5:44pm UTC](https://www.ruby-forum.com/t/memory-management/117857/1 "2007-10-21T17:44:05Z")

</div>

I am new to Ruby. If I instantiate an object instance with

x = Foo.new

should I set x to nil to free the object instance when it is no longer  
needed?

Can anyone point me to any articles etc. on memory management in Ruby?

Thanks.

---

<div class="post-metadata">

**Author:** ![Bazsl](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/ad7895/32.png) [@Bazsl](https://www.ruby-forum.com/u/Bazsl)\
**Post date:** [October 21, 2007, 6:15pm UTC](https://www.ruby-forum.com/t/memory-management/117857/2 "2007-10-21T18:15:40Z")

</div>

If you set x to nil, the garbage collector can free the memory because  
there is not a reference to this area.

---

<div class="post-metadata">

**Author:** ![Bazsl](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/ad7895/32.png) [@Bazsl](https://www.ruby-forum.com/u/Bazsl)\
**Post date:** [October 21, 2007, 6:59pm UTC](https://www.ruby-forum.com/t/memory-management/117857/3 "2007-10-21T18:59:36Z")

</div>

Bazsl wrote:

> 

For the most part you don’t need to worry about memory management in  
Ruby. When there are no more references to an object, Ruby’s garbage  
collector will collect the object and make its storage available for  
re-use.

If you want to know more, here’s a good article:  
[http://whytheluckystiff.net/articles/theFullyUpturnedBin.html](http://whytheluckystiff.net/articles/theFullyUpturnedBin.html).
