From: Jeremy Bopp Date: 2010-12-07T14:16:43+09:00 Subject: Re: Manual Memory Management and Automatic Garbage Collection On 12/06/2010 10:54 PM, Tridib Bandopadhyay wrote: > Yes When I can see my message when I run my GC.start().So When does the > garbage collector comes into play?.When we call them or isn't it > automatic after each object declaration it will always come for > cleaning. Garbage collection is expensive, so the garbage collector's operation is usually postponed until there is a large enough unit of work to warrant its cost of operation. The nice thing about this is that the GC doesn't have to run at all for sufficiently simple scripts. This will make such scripts much faster than if you run the GC as a result of every object's allocation. > But can't I see the message when I am running a program of my own. If you want to see the GC run on its own, you need to cause enough objects and memory to be allocated to trigger it. I can't personally say what that trigger is, but it's probably a safe bet that allocating some large number of objects is one such trigger. Walton's example does that by creating a new string in each iteration of the while loop. > Secondly how does the make command do interpret the gc.c file into > *.ext?Is there any mechanism?. I covered this to some extent in another response in this thread. Obviously, there is a mechanism or you wouldn't get a ruby program to run with your scripts in the first place. ;-) The C compiler is used under the covers, and the make program automates the process. Why do you ask? Do you suspect that your changes are not making it into your ruby program for some reason? From the sound of things, you don't really have much of a grasp on the theory of garbage collection. You might find your task much easier if you go read up more on the general topic and perhaps some discussions of particular implementations. You should find plenty of that information if you search around for Java garbage collection for instance. Without more of a background in the theory, it's going to take you much more time to understand Ruby's implementation. -Jeremy