# Newbie: need to delete object in loop

**URL:** <https://www.ruby-forum.com/t/newbie-need-to-delete-object-in-loop/118990>\
**Category:** Rails\
**Created:** [November 1, 2007, 11:49pm UTC](https://www.ruby-forum.com/t/newbie-need-to-delete-object-in-loop/118990 "2007-11-01T23:49:39Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![alii](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/58956e/32.png) [@alii](https://www.ruby-forum.com/u/alii)\
**Post date:** [November 1, 2007, 11:49pm UTC](https://www.ruby-forum.com/t/newbie-need-to-delete-object-in-loop/118990/1 "2007-11-01T23:49:39Z")

</div>

Hi, sorry for this rather simplistic question, but I can’t think of a  
good way of googling the answer (just been trying for 20 mins).  
Anyway… so I have this rather simplistic piece of code:

\<% for artwork in @artworks %\>

\<% if artwork.medium\_id %\>  
\<% medium = Medium.find(artwork.medium\_id) %\>  
\<% end %\>

\<% if medium %\>

\<%= medium.name %\>

  
\<% end %\>

\<% end %\>

There are 6 artworks, but only the first one has a medium\_id, the others  
are not set. When the code runs the medium is picked up in the first  
iteration of the loop, and then printed each subsequent iteration.

I naively assumed that “medium” would be destroyed at the end of each  
loop, but it seems I was wrong. Is there any way for me to force its  
destruction?

cheers,

ali

---

<div class="post-metadata">

**Author:** ![alii](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/58956e/32.png) [@alii](https://www.ruby-forum.com/u/alii)\
**Post date:** [November 1, 2007, 11:58pm UTC](https://www.ruby-forum.com/t/newbie-need-to-delete-object-in-loop/118990/2 "2007-11-01T23:58:10Z")

</div>

> Hi, sorry for this rather simplistic question, but I can’t think of a  
> good way of googling the answer (just been trying for 20 mins).  
> Anyway… so I have this rather simplistic piece of code:
> 
> \<% for artwork in @artworks %\>

\<% medium = nil %\>
