This article was previously published under Q138398
This article has been archived. It is offered "as is" and will no longer be updated.
After creating an OLE object using the CREATEOBEJCT() function, releasingthat object does not remove the OLE application session from memory.
For Visual FoxPro to remove certain OLE application session objects frommemory, the OLE application must be terminated. For example, after runningthe following code, three instances of Microsoft Excel remain in memory:
FOR i = 1 TO 3 oObject = CREATEOBJECT('Excel.Application') RELEASE oObject ENDFOR
To end each Microsoft Excel session before reentering the FOR loop, theMicrosoft Excel session must first be terminated. For example:
FOR i = 1 TO 3 oObject = CREATEOBJECT('Excel.Application') oObject.Quit RELEASE oObject ENDFOR
In this example, Microsoft Excel is told to quit, and then the codereleases the memory variable in Visual FoxPro by using the oObject.Releasecommand. 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 previousexample, Microsoft Excel was used. Microsoft Excel version 7.0 is designedto remain in memory after a OLE object is released. However, other programsmay behave differently. For example, Microsoft Word version 7.0 terminateswith just a RELEASE command.
For more information on how your program will handle an OLE AutomationRELEASE command, please refer to that program's documentation or refer tothe vendor of that program.
Steps to Reproduce Behavior
Run this code:
FOR i = 1 TO 3 oObject = CREATEOBJECT('Excel.Application') WAIT WINDOW 'Created Excel Object' + STR(i) RELEASE oObject ENDFOR
View the Windows Task List, and notice that three sessions of Microsoft Excel remain in memory.