From: brabuhr@... Date: 2010-01-16T05:52:29+09:00 Subject: Re: WIN32OLE memory leaks Jan 13, 2010, Chuck Remes: > Jan 12, 2010, Luis Lavena: >> Jan 12, 2010, Chuck Remes: >>> In my ruby code I am making a call out to a COM object that is >>> returning an array of objects. I extract some information from these >>> objects and then request a new batch to do the same work all over again. >>> >>> Even though I am clearing the received array out, my program slowly >>> leaks memory until it hits its limit (around 1.4 GB on Windows) and >>> dies. >> >> Also, if this can be reproducible with any COM object, include a >> sample script for us to reproduce in other Windows version and Ruby >> version combinations. > > Here's some code. This is running against 1.8.6-p383 (from > rubyinstaller.org) on Windows XP SP3 plus all the latest patches (Windows > Update runs weekly). > > ... > > I have a method that makes a function call on the COM object > (#request_data). When the function has data to return, it generates a > "DataResolved" event which triggers my callback which was registered once at > the beginning of execution. The callback calls #save and loops through the > collection and pulls some properties into a hash which then gets inserted > into mongodb. When the collection is exhausted, I go back to #request_data > and make another call on the COM object to request the next batch. > > The collection returned is usually around 30MB. I don't leak all 30MB each > time through; it leaks a big percentage of it though (30 to 50%). > > When Task Manager tells me the ruby.exe process is taking up around 1.4GB, > the process just exits. > > Unfortunately this application is not available to the general public so I > can't provide a script for someone to independently verify this. :( I've never used it but "a simple memory leak detector for ruby": http://codeforpeople.com/lib/ruby/dike/dike-0.0.4/README Or, maybe roll your own: def object_count count = Hash.new(0) ObjectSpace.each_object{|o| count[o.class] += 1} count end require 'pp' loop { do_stuff pp object_count }