Hi Tridib,

I'll try to explain what Garth is trying to say.

There is a module called ObjectSpace in ruby
(http://corelib.rubyonrails.org/classes/ObjectSpace.html#M001607). This
will help program to interact with the garbage collector. So using an
ObjectSpace, you can create a finalizer proc to free the resources of an
object.

By default, objects are destroyed by the Garbage collector. But still
you can ensure using ObjectSpace module.

Here is an example:

class DestroyObject
  def initialize
    # Adds a proc as finalizer, this will be called after the object was
destroyed
    # Source:
http://www.ruby-doc.org/core-1.9.3/ObjectSpace.html#method-c-define_finalizer
    ObjectSpace.define_finalizer(self,
self.class.method(:finalize).to_proc)
  end

  # This should be a class method, not an instance method
  # For reason,
http://www.mikeperham.com/2010/02/24/the-trouble-with-ruby-finalizers/
  def self.finalize(id)
    puts "Object #{id} dying at #{Time.now}"
  end
end

DestroyObject.new

# Initiates garbage collection
# Source:
http://www.ruby-doc.org/core-1.9.3/ObjectSpace.html#method-c-garbage_collect
ObjectSpace.garbage_collect

I hope it clears your query on finalizer.

Even I'm not expert on this, but this thread helped me to learn about
this. If anyone finds any mistakes, welcome to correct.

Cheers,
Vimal

-- 
Posted via http://www.ruby-forum.com/.