# Deleting objects?

**URL:** <https://www.ruby-forum.com/t/deleting-objects/68844>\
**Category:** Ruby\
**Created:** [February 15, 2006, 9:52pm UTC](https://www.ruby-forum.com/t/deleting-objects/68844 "2006-02-15T21:52:28Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![PaatschS\_Bernd](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/fbc32d/32.png) [@PaatschS\_Bernd](https://www.ruby-forum.com/u/PaatschS_Bernd)\
**Post date:** [February 15, 2006, 9:52pm UTC](https://www.ruby-forum.com/t/deleting-objects/68844/1 "2006-02-15T21:52:28Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![PaatschS\_Bernd](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/fbc32d/32.png) [@PaatschS\_Bernd](https://www.ruby-forum.com/u/PaatschS_Bernd)\
**Post date:** [February 15, 2006, 11:18pm UTC](https://www.ruby-forum.com/t/deleting-objects/68844/2 "2006-02-15T23:18:00Z")

</div>

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 C. Phone : (64)(3) 358 6639  
Tait Electronics Fax : (64)(3) 359 4632  
PO Box 1645 Christchurch Email : removed\_email\_address@domain.invalid  
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.
