From: "Victor \"Zverok\" Shepelev" Date: 2006-10-29T05:23:44+09:00 Subject: Re: How to understand why object is not collected? From: Eero Saynatkari [mailto:ruby-ml@kittensoft.org] Sent: Saturday, October 28, 2006 11:20 PM >On 2006.10.29 03:26, Victor Zverok Shepelev wrote: >> Hi all. >> >> Here's a problem. >> >> I have some object of MyClass with complex "freeing" logic, and I want to >> test this logic. >> > >Hard to say what is going wrong but the solution is simple. Whenever >you have a resource that must be released, do it explicitly. The way >this is usually implemented is either: > > f = File.open 'foo' > puts f.read > f.close > >Or, more conveniently > > File.open('foo') {|f| puts f.read} > >The block-form uses ensure to make sure the file handle gets closed. I know this (I was C++ guy foe many years, so RAII is my breath), but can't use. My objects are HTML DOM elements and I want to be sure they are GC'd when detached from DOM and have no other references. V.