Forum: Ruby Deleting objects?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Fd870ca69f1243766bd8697ea3415df2?d=identicon&s=25 Paatsch, Bernd (Guest)
on 2006-02-15 21:52
(Received via mailing list)
Hello,

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?

-Bernd
D812408537ac3a0fa2fec96eb8811559?d=identicon&s=25 John Carter (Guest)
on 2006-02-15 23:18
(Received via mailing list)
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.
This topic is locked and can not be replied to.