Deleting objects?

My mistake:

I set an variable to nil outside the loop and then the second time around it
was not nil and therefore not populating the hash as I expected.



-----Original Message-----
From: John Carter []
Sent: Wednesday, February 15, 2006 2:17 PM
To: ruby-talk ML
Subject: Re: Deleting objects?

On Thu, 16 Feb 2006, Paatsch, Bernd wrote:

My little program works one. However fails when I add a loop two run
it multiple times with different input data.

I believe this might be due to objects that have not been delete. Is
there a way to delete objects other than setting the variable to nil?


$global_var = {}

def my_func( line)
   # Uses $global_var, $global_var just accumulates objects, never letting
   # go.

STDIN.each_line do |line|
   my_func( line)

# Now if we use a local variable like so...

def my_func( line)
   local_var = {}
   # We get a fresh new hash every loop, old hash and old objects we held
   # on to are garbage collected automagically every time we leave the
   # scope of the variable.

To really debug your problem we need to see your code.

John Carter Phone : (64)(3) 358 6639
Tait Electronics Fax : (64)(3) 359 4632
PO Box 1645 Christchurch Email :
New Zealand

Carter's Clarification of Murphy's Law.

"Things only ever go right so that they may go more spectacularly wrong

From this principle, all of life and physics may be deduced.