From: Kevin Smith Date: 2001-01-12T15:35:45+09:00 Subject: [ruby-talk:9184] Re: Any way to delete object obviously? and.u wrote: >I want to delete object obviously like in Python >a = C.new >del a I was waiting for someone else to respond, but I haven't seen any answers, so I'll try. There is no way to explicitly delete an object. If such a call did exist, it could only take effect after the last reference to that object had been released. When the last reference is release, the object becomes available to be deleted. That's the beauty of garbage collection. I guess the closest you could get would be something like: a = C.new a = nil # so nothing refers to that object any more GC.start >And I want to know why no destructor in Ruby object. As a C++ guy, this bothered me about Java, and then Ruby. In practice, having now written a couple thousand lines of Ruby, it just isn't an issue. Ruby has a nice idiom that eliminates one common need for destructors. Take a look at the File#open method, and how you can pass a block. The file will automatically be closed when the block is finished. You could apply this to other resources that need to be freed when the operation is complete. Ruby does also allow you to insist that a particular proc be called when an object is about to be destroyed. ObjectSpace.defin_finalizer. I would encourage you to avoid using it unless you find a really weird corner case that requires it. It's much simpler to just go with the Ruby way of doing things. Kevin