From: Sean Middleditch Date: 2002-02-24T14:17:24+09:00 Subject: Re: Object/Memory Management On Sat, 2002-02-23 at 22:01, Sean O'Dell wrote: > Dave Thomas helped me with ideas about how to handle the lack of object > destructors, so I believe I'm covered there. I can still think of reasons > why I would need destructors, but so far I've been able to imagine ways > around it and I think the new way of doing things is simply going to become > my own personal paradigm while programming in Ruby. If you are coming from a C++ background, then why not just define a "close" method for your objects? It can't be any more cumbersome than in C++, in which you would have add to explicitly call delete anyhow. Remember, in Ruby, you can't define objects on a stack, like this C++ code: object instance (arg); It's all more like: object *instance_ptr = new object (arg); Ruby, of course, deletes the object from memory when it's no longer used. In C++, no matter what, you'd have to explicitly delete the object: delete (instance_ptr); Which is more or less an explicit call to the destructor, plus the cleanup code. In Ruby, you don't have to deal with the cleanup, but you still have to make the explicit call to the destructor, just like in C++: instance.destroy () If you are talking about putting objects on the stack, like in C++, realize that this can't be cleanly done in a GC language. You have to pick - do you want a stack, or do you want a GC? They can't efficiently exist together (yes, Lua and others have stacks and GC, but their stacks don't work quite the same way as the C/C++ languages do; or they are just easily broken and crashable). It's a choice of: (A) do you want the ease of letting the stack cleanup for you, or (B) do you want the ease of never dealing with memory management, again, ever. > > Thanks for the help, > > Sean > >