Q:

ruby high use of memory, possibly leakage

I am using Ruby 1.9.3p0. The program that I wrote uses a lot of Memory when I run it for more than 4 hours. I am using the following gems:
require 'rubygems' 
require 'nokogiri'
require 'open-uri'
require 'cgi'
require 'domainatrix'

This following code is run for more than 10.000 times, and I suspect it may cause a leak.
  File.open('output.txt', 'a') do |file|
            output.each_line do |item|
                    item = item.match(/^[^\s]+/)
                    item = item.to_s
                    if item = item.match(/[a-zA-Z0-9\-_]+\..+\.[a-zA-Z]+$/)
                    item = item.to_s
                            if item.length > 1
                                    #puts "item: #{item}"
                                    #item = item.to_s
                                    item = Domainatrix.parse(item)
                                    puts "subdomain: #{item.subdomain}"
                                    if (item.domain == domain)
                                            file.puts item.subdomain
                                            puts item.subdomain
                                    end
                            end
                    end
            end
    end

On the other hand, I am using a hash table to store every link.
What do you think may cause the Ruby to use a lot of memory?
UPDATE
Also I believe File.open should be closed after it is used. Is it true?

A:

first don't require 'rubygems' not required in ruby 1.9.

you forgot to use ')' after if condition.

   if (item.domain == domain

yes File.open closes the file.

