Article ID: 238987 - Last Review: August 18, 2005 - Revision: 3.3

PRB: Office Application Remains in Memory After Program Finishes

This article was previously published under Q238987
Expand all | Collapse all

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 these 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, such as Open or New, that return an IDispatch * (LPDISPATCH), and ignoring the return value. If you are, then you are abandoning this returned interface and you will need to change your code so that you release this IDispatch * 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. 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 shut down 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.

APPLIES TO
  • Microsoft Office XP Developer Edition
  • Microsoft Office 2000 Developer Edition
  • Microsoft Outlook 98 Standard Edition
  • Microsoft Office 97 Standard Edition
  • Microsoft Office 95 Standard Edition
  • Microsoft Visual C++ 4.0 Standard Edition
  • Microsoft Visual C++ 5.0 Enterprise Edition
  • Microsoft Visual C++ 6.0 Enterprise Edition
  • Microsoft Visual C++ 5.0 Professional Edition
  • Microsoft Visual C++ 6.0 Professional Edition
  • Microsoft Visual C++, 32-bit Learning Edition 6.0
Keywords: 
kbfaq kbprb KB238987
 

Article Translations

 

Related Support Centers