Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can an object be released???

Status
Not open for further replies.

baileybelle

Technical User
Jul 22, 2002
10
US
What is the proper way to release an object from memory in foxpro? For example, if I created an instance of an Excel application using the following:

objExcel = CREATEOBJECT("Excel.Application")
 
Hi

objExcel = CREATEOBJECT("Excel.Application")

Excel application is released when you call the applications release method. In this case..

objExcel.Quit

Then.. the object is relased fom VFP when.. you issue the command..

RELEASE objExcel

The object can be indirectly released when you say..
objExecl = NULL

But the object stays as a NULL object or NULL variable.

Same way when a form is insttiated..
oForm = CREATEOBJECT(form).. whatever syntax..

oForm.Release() releases the form... but the oForm by itself is not relased. You have to issue..
RELAASE oForm

:) ramani :)
(Subramanian.G),FoxAcc, ramani_g@yahoo.com

 
'oForm.Release() releases the form... but the oForm by itself is not released. You have to issue..
RELEASE oForm'

One way of ensuring that always happens is to put RELEASE oForm in the .UnLoad() event of the form itself.
FAQ184-2483 - the answer to getting answered.​
Chris [pc2]
 
MikeLewis

Or simply let oForm go out of scope? Is that possible?

That depends if its public or local (most of the time in automation its public).
I would use:
oFORM.Release()
oForm=.NULL.

Mike Gagnon

If you want to get the best response to a question, please check out FAQ184-2483 first.
 
Mike

What I should have explained is that I always make an object reference to a form a PUBLIC variable - that way the object reference is always in scope regardless of the structure of the application, and thus you cannot lose the form if the LINKED argument is inadvertedly used as well.

Using the .UnLoad() event of a form to release the reference means that, as a developer, you cannot 'forget' to release the reference elsewhere in the project and end up with a dangling object reference with all the hassle that can bring.

Assuming you are using a subclassed form and you use a naming convention for your forms whereby the name of the form is the same as the name of the .scx, you can use the following code in the .UnLoad() event of the base class form.

lcFormName = [o] + THIS.name
RELEASE (lcFormName)
FAQ184-2483 - the answer to getting answered.​
Chris [pc2]
 
Chris,

What I should have explained is that I always make an object reference to a form a PUBLIC variable

Yes, that's all very clear. Thanks.

I recently wrote a form manager object which keeps track of which forms are open and returns an object reference to the active form or to a form with a give name. It's a bit simplistic, but it does make it easy to access the PEMs of any running form.
Mike Lewis
Edinburgh, Scotland
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top