# Will it save memory if I keep using one instance name?

**URL:** <https://www.ruby-forum.com/t/will-it-save-memory-if-i-keep-using-one-instance-name/86619>\
**Category:** Ruby\
**Created:** [February 23, 2007, 8:36pm UTC](https://www.ruby-forum.com/t/will-it-save-memory-if-i-keep-using-one-instance-name/86619 "2007-02-23T20:36:48Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![a\_a](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/7ea924/32.png) [@a\_a](https://www.ruby-forum.com/u/a_a)\
**Post date:** [February 23, 2007, 8:36pm UTC](https://www.ruby-forum.com/t/will-it-save-memory-if-i-keep-using-one-instance-name/86619/1 "2007-02-23T20:36:48Z")

</div>

All all! I’m a newbie here, please look my example code:

r = Page.find :all, :conditions =\> “is\_default = ‘true’”  
assert\_equal 1, r.length  
r = Page.create NEW\_INSTANCE\_DATA  
assert !r.new\_record?  
r = Page.find :first, :conditions =\> “name = ‘privacy\_policy’”  
assert\_not\_nil r  
assert r.is\_default

if I writing this way~ it there any effect to saving memory?  
(because I think the old instance are always released in time.)

---

<div class="post-metadata">

**Author:** ![a\_a](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/7ea924/32.png) [@a\_a](https://www.ruby-forum.com/u/a_a)\
**Post date:** [February 23, 2007, 10:14pm UTC](https://www.ruby-forum.com/t/will-it-save-memory-if-i-keep-using-one-instance-name/86619/2 "2007-02-23T22:14:02Z")

</div>

On 2/23/07, a\_a [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> if I writing this way~ it there any effect to saving memory?  
> (because I think the old instance are always released in time.)

The instance is released any time after the interpreter detects you  
don’t use it any more. That means:

1. if you assign another object to ‘r’ you lose the previous value and  
it’s ready to be destroyed.

2. the same effect you can achieve using different vars (a,b,c etc.)  
if you assign nil to them (a = Page.find… ; a = nil; b= etc.)

3. you can never tell when the garbage collecting will take place. you  
just know it will happen sometime.
