From: luke gruber Date: 2011-08-02T10:12:01+09:00 Subject: Re: system stack error in ObjectSpace.each_object > I assume you created some weird kind of recursion via > define_finalizer. I'm not really sure what's going on. Can you > explain what your code is supposed to do? > robert Yeah, it was just for fun and to learn some of these metaprogramming methods, but what I was meaning to do was to be able to make a 'leader' object of, say, class Foo. Upon choosing the leader object, you have to choose a subordinate class to lead (which could be the same class as the leader object, ie: Foo. Basically the implementation was to take all the objects of the subordinate class, then override all of the instance methods in the leader object's class by putting new methods in the leader's singleton class with the same name as the instance methods in the leader's class. Every time these new 'leader' methods are called (ie: the leader responds to a method that's defined in the leader's own class), it sends the same method (with the same args &block) to all the subordinate objects. Anyway, I'm just having fun and I know playing with ObjectSpace can lead to some weird errors, but this error seems to be consistent enough in that I kept on running into it until I added that statement modifier. Thanks for checking it out. =========================== 1) >If you need to keep track of all the objects of class Foo, then it would >be better to make some sort of container which keeps track of them >explicitly. 2) >ObjectSpace is (a) inefficient, because it scans *every* object in the >system, and (b) unreliable, because it may show you objects which should >have died, but some reference is being held somewhere. >Brian. 1) For the container idea, how would you go about doing this? 2) As for ObjectSpace returning dead objects, is there a way to force GC during runtime? Also, does taking all variables that point to an object and pointing them to nil effectively dangle an object like this? Thanks Robert and Brian, -Luke -- Posted via http://www.ruby-forum.com/.