PRB: RELEASE May Not Remove OLE Objects from Memory

Article translations Article translations
Article ID: 138398 - View products that this article applies to.
This article was previously published under Q138398
This article has been archived. It is offered "as is" and will no longer be updated.
Expand all | Collapse all

On This Page


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


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')
       RELEASE oObject

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')
       RELEASE oObject

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.


This behavior is by design.


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)
           RELEASE oObject
  2. View the Windows Task List, and notice that three sessions of Microsoft Excel remain in memory.


Article ID: 138398 - Last Review: February 24, 2014 - Revision: 1.2
  • Microsoft Visual FoxPro 3.0 Standard Edition
  • Microsoft Visual FoxPro 5.0 Standard Edition
  • Microsoft Visual FoxPro 5.0a
  • Microsoft Visual FoxPro 6.0 Professional Edition
kbnosurvey kbarchive kbprb KB138398

Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from