From: Paul Brannan Date: 2004-03-05T00:58:31+09:00 Subject: Re: destructor? On Thu, Mar 04, 2004 at 10:04:42PM +0900, Robert Klemme wrote: > For completeness reasons let me mention that there are finalizers, but > they don't have the same properties as constructors of C++, the most > striking difference beeing that you can't control the point in time when > they are called. See: > > http://www.rubycentral.com/book/ref_m_objectspace.html#ObjectSpace.define_finalizer Another less obvious (and very important) difference between C++ destructors and Ruby finalizers: - C++ destructors are called as the object is being destructed (member variables are still accessible from the destructor), but - Ruby finalizers are called after the object is destroyed (so the object is no longer around and if the object has resources that need to be cleaned up, the finalizer must hold a reference to them). See also: http://www.rubygarden.org/ruby?RubyIdioms http://www.rubygarden.org/ruby?ObjectsNotGetFinalized http://www.rubygarden.org/ruby?DiscussionOnUsingFinalizers http://www.rubygarden.org/ruby?RubyFromCpp Paul