From: "Paatsch, Bernd" Date: 2006-02-16T07:46:12+09:00 Subject: Re: Deleting objects? ------_=_NextPart_001_01C63281.4E52C1C2 Content-Type: text/plain 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. -Bernd -----Original Message----- From: John Carter [mailto:john.carter@tait.co.nz] 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? Example... $global_var = {} def my_func( line) # Uses $global_var, $global_var just accumulates objects, never letting # go. end STDIN.each_line do |line| my_func( line) end # 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. end 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 : john.carter@tait.co.nz New Zealand Carter's Clarification of Murphy's Law. "Things only ever go right so that they may go more spectacularly wrong later." From this principle, all of life and physics may be deduced. ------_=_NextPart_001_01C63281.4E52C1C2--