title: Ruby/Mechanize Any way to drain RAM? -> failed to allocate memory
body: <p>I've built a code which vote for me on a website...</p>
  
  <p>The Ruby script works quite well but after few minuts this script stop with this errors : <a href="http://i.stack.imgur.com/PuyHC.png" rel="nofollow">link of the screen-shot</a></p>
  
  <p><strong>So I've inspected the windows task manager and the memory alocate to the ruby.exe grow after each loop !</strong></p>
  
  <p>here is the incriminate peace of code :</p>
  
  <pre><code>class VoteWebsite
          def self.main
          agent = Mechanize.new
          agent.user_agent_alias = 'Windows Mozilla'
      while $stop!=true
          page = agent.get 'http://website.com/vote.php'
          reports_divs = page.search(".//div[@class='Pad1Color2']")
          tds = reports_divs.search("td")
          i = 3;j = 0;ouiboucle=0;voteboucle=0
          while i &lt; tds.length
              result = tds[i].to_s.scan(/&lt;font class="ColorRed"&gt;&lt;b&gt;(.*?) :&lt;\/b&gt;&lt;\/font&gt;/)
              type = result[0].to_s[2..-3]
              k=i
              case type
              when "Type of vote"
                  j= i+1;i += 4
                  result2 = tds[j].to_s.scan(/&lt;div id="btn(.*?)"&gt;/)           
                  id = result2[0].to_s[2..-3]
                  monvote=define_vote($vote_type, tds[k].to_s, $vote_auto)
                  page2 = agent.get 'http://website.com/AJAX_Vote.php?id='+id+'&amp;vote='+monvote
                  voteboucle+=1
                  .
                  .
                  .
              else
                  .
                  .
                  .
              end
          end     
      end
      end
  end
  VoteWebsite.main
  </code></pre>
  
  <p>I think that declaring all the variables inside the method to Global variable should fix this probleme but the code is quite big and there is planty of variables inside this method.</p>
  
  <p><strong>So is there any way (any Ruby instruction) to drain all this variable at the end of each loop ?</strong></p>