"Too many open files" error

Example code, on Ruby 1.8.6:
require 'resolv'
t0 = Time.now
(1..500).each do |a|
    begin
      a = Resolv::DNS.new.getaddress("www.example.dom").to_s
    rescue Resolv::ResolvError
      a = "Hahahahaa"
  end
end
puts "#{(Time.now - t0) / 500} second per."

Error:
c:/ruby/lib/ruby/1.8/resolv.rb:572:in `initialize': Too many open files
(Errno::EMFILE)

···

___________________

How can I prevent this error from happening? Can I do manual garbage
collection and delete each DNS.new Object at the end of each iteration?
Is there a better idea out there?

Thanks,

--Aldric

*sigh* Never mind, I was being stupid - just create one object and then
reuse that object over and over as needed! Unless I absolutely need to
create more objects.. Let's not do that.

--Aldric