From: Ritwik Banerjee Date: 2010-10-29T23:26:53+09:00 Subject: Re: Ruby 1.9.1 linear memory increase in a simple for loop. Robert Klemme wrote in post #958018: > On Fri, Oct 29, 2010 at 3:17 PM, Ritwik Banerjee > wrote: >> 1, 1],[0, 1, 1, 1, 1, 1, 1, 1],[0, 1, 0, 1, 1, 0, 1, 1]] >> # ObjectSpace.garbage_collect >> codes with lots of references, and in those cases the memory rise is >> exponential. In the above loop, invoking garbage collection manually >> (it's commented out in the snippet above) slows the memory increase, but >> only by a constant factor. >> For example, if the loop used up 30 kB in 100 iterations originally, it >> uses up 30kB in 500 iterations after invoking garbage collection >> manually. >> >> Understanding this is critical for me since I am dealing with matrices >> of enormous sizes, so even a small memory leak can jeopardize my >> project. > > AFAIK there is a certain memory threshold below which the interpreter > never does GC. This helps make small scripts run fast. You probably > need to let your program run much longer and monitor memory to see the > long term effect. Only if you see dramatic increase in the long run > you may conclude that you found a leak IMHO. > > Kind regards > > robert Thanks Robert. You are absolutely right. Even I think Ruby doesn't invoke GC for short codes. The code I provided was a mere example. Even in a much larger code, the nature of the problem remains exactly the same: linear increase in memory and number of objects in memory heap; while manual invocation of GC cuts down the memory increase by a constant factor. - Ritwik -- Posted via http://www.ruby-forum.com/.