PRB: Office Application Remains in Memory After Program Finishes
ID: Q238987
|
The information in this article applies to:
-
Microsoft Visual C++, 32-bit Editions, versions 4.0, 5.0, 6.0
-
Microsoft Outlook 98
-
Microsoft Office 97 for Windows
-
Microsoft Office for Windows 95, version 7.0
-
Microsoft Office 2000 Developer
SYMPTOMS
The Office application you are automating continues to reside in memory after your Visual C++ program finishes executing.
CAUSE
Most likely the application is still in memory because you have forgotten to release an acquired interface.
RESOLUTION
Here are some general suggestions and things to looks for when trying to determine the cause of the problem:
- If you're using #import, it is very likely you could be running into one of the reference-counting bugs associated with it. Often times the bugs can be worked around, but usually it is preferred to use one of the other Automation methods. #import doesn't work very well with the Office applications because its type libraries and use are fairly complex. Also, such reference counting problems are hard to track down because a lot of the interface-level COM calls are behind-the-scenes when using #import.
- Check to see if you are calling any methods that return an IDispatch * (LPDISPATCH), such as Open or New, and ignoring the return value. If you are, then you are abandoning this returned interface and will need to change your code so that you release it when no longer needed.
-
Gradually comment out sections of your code until the problem disappears, then add it back judiciously to track down where the problem starts.
- Note that some applications will stay running if the user has "touched" the application. If this occurs while you are automating, then the application will probably stay running afterwards. The Office applications have a "UserControl" property on the Application object that you can read/write to change this behavior.
-
Also, some applications will decide to stay running if enough user-interface "action" has occurred. If you intend for the application to exit, then call its Quit() method on the Application object. Word will shutdown regardless of its reference count when Quit is called. This isn't expected COM behavior. Excel, however, will properly just hide itself but stay running until all outstanding interfaces are released. In general, you should release all outstanding references, and only call Quit() if you intend the application to quit.
Additional query words:
Keywords : kbOutlook kbVC kbVC400 kbVC500 kbVC600 kbOffice2000 kbDSupport
Version : WINDOWS:7.0,97,98; winnt:4.0,5.0,6.0; :
Platform : WINDOWS winnt
Issue type : kbprb
|