From: James Tucker Date: 2007-05-27T23:53:01+09:00 Subject: Re: WIN32OLE: Excel Object is not GCed, except within IRB (Was: How to completely terminate a WIN32OLE Excel object?) Sven Suska wrote: > Hello James, > > James Tucker schrieb: > >> I can't replicate this: >> >>>> require 'win32ole' >>> >> [... skipping irb session ...] > > > This is truely strange! > > Thanks for pointing this out! > > When I tried this with IRB on my machine, > I got the same result: > Excel termination worked normally. > > So there must be some difference > when the is executed as a Ruby file vs. via IRB. Interesting indeed! I can replicate from a .rb file. In fact, loading the .rb in irb also works in the correct manner, on the contrary, if I load the .rb in my hacked version of IRB, it does not. This seems almost like it is hardcoded to work for irb, or it is something to do with the way in which handles are being processed. I have also noticed a similar behavior with shell execution. A GC.start will clear used file handles from `` and system() calls in IRB, and if documentation I have read elsewhere is correct, this is not the case for 'normal execution'. Time to plough through IRBs source tree, and start tracing. > So far, I have no idea what it could be. > I have set both RUBYOPT and RUBLIB to empty strings, > I've run the file via SciTe and on the console (ruby filename.rb) > -- the Excel object persists under all those conditions. > It's only within IRB that it is cleaned up properly. > > Both my Ruby186 and 185 installations were done with > the one-click installer. (if that is of any significance) > > > I would appreciate any further help on this issue. > > Thank you > Sven > > >> >> >> >> >> Sven Suska wrote: >> >>> Hello, >>> >>> I can't get rid of Excel, if I have ever called it, >>> even with such a simple script: >>> >>> ---------- code starts -------------- >>> require 'win32ole' >>> >>> def puts_win32ole_objects >>> res = [] >>> ObjectSpace.each_object do |o| >>> res << o if o.is_a? WIN32OLE >>> end >>> puts res.inspect >>> end >>> >>> puts_win32ole_objects # --> empty >>> xl = WIN32OLE.new('Excel.Application') >>> puts_win32ole_objects # --> one object >>> xl.Quit >>> xl = nil >>> GC.start # anything else I could do??? >>> puts_win32ole_objects # --> the object is still there >>> sleep 5 >>> --------------------------------------------- >>> And also the Excel process remains running in Windows. >>> >>> Btw, even after the xl.Quit, the object remains fully functional, >>> so I could call o.Visible, o.Workbooks.Open(...) etc., it o were >>> the object (retrieved from ObjectSpace). >>> >>> When the Ruby process is terminated (after sleep), the >>> Excel process will also terminate. >>> >>> So, what's the proper way to handle this? >>> >>> I've found the WIN32OLE.ole_free method, but they say >>> that it is for debugging only. >>> >>> >>> Thanks for your help >>> >>> Sven >>> >>> >>> >>> >> >> >> > > >