Masaki Suketa
7/30/2007 11:56:00 AM
Hello, sorry for being too late to reply.
In message "Re: win32ole: application.quit() leave process running"
on 07/07/09, Todd Burch <promos@burchwoodusa.com> writes:
> Yes, after more searching, I found a few threads here that deal with
> this same issue. It appears that this is a problem.
>
> I am going to "work around this" with the following code:
>
> xlapp.activeworkbook.close() ;
> xlapp.ole_free ;
> xlapp = nil ;
> GC.start ;
>
> This causes my workbook to close, leaving an "empty" excel session.
> When I subsequently manually close (red x) the excel session, it
> terminates completely and can no longer be seen in Task Manager.
Excel process is terminated if only if the xlapp object is GCed.
In the following code, if the ruby clean the xlapp object,
then Excel process is terminated.
xlapp.quit
xlapp = nil
GC.start # (*1)
But unfortunatelly, xlapp is not always GCed in GC.start(*1).
Sometimes xlapp may be GCed and sometimes not.
This is Ruby GC behavior.
If you want to terminate Excel process, use WIN32OLE#ole_free,
or WIN32OLE.ole_free.
xlapp.quit
WIN32OLE.ole_free(xlapp) # or xlapp.ole_free
xlapp = nil
GC.start
Regards
Masaki Suketa