From: James Tucker Date: 2007-05-27T16:37:40+09:00 Subject: Re: How to completely terminate a WIN32OLE Excel object? I can't replicate this: >> require 'win32ole' => true >> ?> def puts_win32ole_objects >> res = [] >> ObjectSpace.each_object do |o| ?> res << o if o.is_a? WIN32OLE >> end >> puts res.inspect >> end => nil >> ?> puts_win32ole_objects # --> empty [] => nil >> xl = WIN32OLE.new('Excel.Application') => # >> xl.Visible => false >> puts_win32ole_objects # --> one object [#] => nil >> puts `tasklist | find /I "excel.exe"` EXCEL.EXE 508 Console 0 10,132 K => nil >> xl.Quit => nil >> xl = nil => nil >> GC.start # anything else I could do??? => nil >> puts_win32ole_objects # --> the object is still there [] => nil >> puts `tasklist | find /I "excel.exe"` => nil 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 > > > >