PRB: RELEASE May Not Remove OLE Objects from Memory

Last reviewed: August 13, 1997
Article ID: Q138398
3.00 WINDOWS kbole kbprb

The information in this article applies to:

  • Microsoft Visual FoxPro for Windows, version 3.0

SYMPTOMS

After creating an OLE object using the CREATEOBEJCT() function, releasing that object does not remove the OLE application session from memory.

RESOLUTION

For Visual FoxPro to remove certain OLE application session objects from memory, the OLE application must be terminated. For example, after running the following code, three instances of Microsoft Excel remain in memory:

   FOR i = 1 TO 3
       oObject = CREATEOBJECT('Excel.Application')
       oObject.Release
   ENDFOR

To end each Microsoft Excel session before reentering the FOR loop, the Microsoft Excel session must first be terminated. For example:

   FOR i = 1 TO 3
       oObject = CREATEOBJECT('Excel.Application')
       oObject.Quit
       oObject.Release
   ENDFOR

In this example, Microsoft Excel is told to quit, and then the code releases the memory variable in Visual FoxPro by using the oObject.Release command. Quit is a method that Microsoft Excel recognizes and can act upon, the actual method for your OLE automation application may differ.

STATUS

This behavior is by design.

MORE INFORMATION

The OLE Automation release method is program specific. In the previous example, Microsoft Excel was used. Microsoft Excel version 7.0 is designed to remain in memory after a OLE object is released. However, other programs may behave differently. For example, Microsoft Word version 7.0 terminates with just a RELEASE command.

For more information on how your program will handle an OLE Automation RELEASE command, please refer to that program's documentation or refer to the vendor of that program.

Steps to Reproduce Behavior

  1. Run this code:

    FOR i = 1 TO 3

           oObject = CREATEOBJECT('Excel.Application')
           WAIT WINDOW 'Created Excel Object' + STR(i)
           oObject.Release
    
    ENDFOR

  2. View the Windows Task List, and notice that three sessions of Microsoft Excel remain in memory.


Additional reference words: 3.00 VFoxWin
KBCategory: kbole kbprb
KBSubcategory: FxinteropOle


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: August 13, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.