From: Alex Gutteridge Date: 2010-11-25T19:13:15+09:00 Subject: Re: Ruby Programming On Wed, 24 Nov 2010 13:02:09 +0900, Tridib Bandopadhyay wrote: > Alex Gutteridge wrote in post #962544: >> On Fri, 19 Nov 2010 10:30:30 +0900, Tridib Bandopadhyay >> wrote: >>> which i tried to print out.? >>> >>> Regards >>> >>> Tridib >> >> Sure. There's also the GC_NOTIFY and GC_DEBUG defines in gc.c and >> GC::Profiler which you can call from Ruby. As people have already >> pointed >> out *any* Ruby program will require memory allocation and hence GC. > > Can you tell me how to call those two?...And do I need to write some > print statement within those one.?? > > Regards There doesn't seem to be any mystery here, just search for GC_NOTIFY in gc.c and set it to true rather than false. E.g. #define GC_NOTIFY 0 becomes #define GC_NOTIFY 1 That change alone prints "start garbage_collect()" whenever garbage_collect() is run: GUTTEA$ ./ruby -e 'GC.start' start garbage_collect() end garbage_collect() Defining RUBY_MARK_FREE_DEBUG in gc.h gives lots more info as well: GUTTEA$ ./ruby -e 'GC.start' start garbage_collect() mark: -> iseq (0x100624900) require @ mark: -> iseq (0x100624cb0) rescue in require @ mark: <- iseq (0x100624cb0) mark: <- iseq (0x100624900) mark: -> iseq (0x100612b90) gem @ mark: <- iseq (0x100612b90) mark: -> iseq (0x10060c950) [.......] I don't see any problem with adding your own debug statements as well if you want: static int garbage_collect(rb_objspace_t *objspace) { struct gc_list *list; rb_thread_t *th = GET_THREAD(); INIT_GC_PROF_PARAMS; if (GC_NOTIFY) printf("start garbage_collect()\n"); printf("WoopWoop\n"); [....] GUTTEA$ ./ruby -e 'GC.start' start garbage_collect() WoopWoop [....] -- Alex Gutteridge