From: Paul Brannan Date: 2002-04-19T10:10:13+09:00 Subject: Re: GC problem in C++ extension On Fri, Apr 19, 2002 at 09:54:09AM +0900, Nobuyoshi Nakada wrote: > It's not predictable when an object will be gargage-collected. The problem is that I need to test to make sure that my code works, by testing: 1) that I'm not keeping any references that I shouldn't be, and 2) I registered my free() function correctly with the garbage collector. The only way I could think of to do this was to assert that the object got garbage collected after calling GC.start. Is there a better way? > In former case, the new object might be stored in the stack, > and marked there. Just my guess. This was what I suspected. So I wrote a function that recurses 1000 times (that seemed to be as much as Ruby would let me recurse). In theory, that should overwrite the value, but Ruby would still not garbage-collect. I thought also that perhaps it wasn't being garbage collected because it didn't need to be. So I wrote a function that would cause a NoMemoryError by setting the virtual memory ulimit to 64M and allocating 1M at a time in an infinite loop, but this just caused Ruby to crash. Additionally, while that VALUE was on the stack, I returned from the function that kept the VALUE on the stack. So the VALUE should lie past the end of the stack, and not between the base and the end. Or is there more to the story than this? (BTW, it seems that on Ruby 1.7, the object doesn't get garbage-collected in either case. It only gets garbage-collected on Ruby 1.6.5). Paul