Memory management

B

Bazsl

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.
 
S

Stéphane Wirtel

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

Tim Hunter

Bazsl said:
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.

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top