a_a
#1
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.)
a_a
#2
On 2/23/07, a_a [email protected] 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:
-
if you assign another object to ‘r’ you lose the previous value and
it’s ready to be destroyed.
-
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.)
-
you can never tell when the garbage collecting will take place. you
just know it will happen sometime.