From: Jeremy Bopp Date: 2010-12-11T01:00:14+09:00 Subject: Re: Manual Memory Management and Automatic Garbage Collection On 12/10/2010 09:37 AM, Tridib Bandopadhyay wrote: > I can see the garbage collector coming when I type. > > ./ruby -e 'GC.start()' > > But I want to know while a code is running the printf statement written > by me should appear. > > Is there any other code to make gc show my message. > > This code is running for infinite time..but not showing the message. > > > i=1 > while (true) > puts "message #{i}" > i+=1 > end > > What are the other ways? > > I need to convince myself that when there is memory allocation the > Garbage collector comes for cleaning with a printf statement stating its > work. Maybe there are optimizations for String objects that circumvent parts of regular garbage collection. Have you tried looking at the memory consumption of your ruby process as you run the while loop? Is memory usage growing over time, or does it plateau at some point? Try using your ruby executable to run some non-trivial projects available online. Once you find one that triggers garbage collection the way you want it, you could try to boil that down to something more concise. Another suggestion would be to pick up a template library such as erb and use that to process some large template files with random data repeatedly. That should hopefully cause some memory growth with something more than simple strings. -Jeremy