Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Testing a objects existence
Message
General information
Forum:
Visual FoxPro
Category:
Object Oriented Programming
Miscellaneous
Thread ID:
00366567
Message ID:
00367484
Views:
23
>If the object is NULL then the object is destroyed and only the variable reference still exists?

Well, if the final refernce does go out of scope or is NULLed, the object should Destroy(). Here's a sample piece of cod etha tmight help:
oTest = createobject('myobject')
oTest2 = oTest
?type('otest') && O
?type('otest2') && O
oTest = .NULL.  
?type('otest') && O
?type('otest2') && O
?isnull(otest2) && .F.
?isnull(otest)  && .T.
oTest2 = .NULL. && "Killed"
?type('otest2') && O
?isnull(otest2) && .T.
oTest3 = oTest
?type('otest3') && O
?isnull(otest3) && .T.

define class myobject as label
	proc destroy
		?'Killed'
	endproc
enddefine
>If the variable reference still exists does it just sit there and take up resources?

The variable refernce could still exist, depending on the scope of the variable. The object could still exist if there is still one reference to it somwhere. In the case of a form, a form can still exist, yet there are no valid object refrences except in the _vfp.forms array and activeform properties. Do objects still exist with no refernce and waste resources? I can;t say positivly, but I don't think that how it works.

>And finally, I've always assumed that VFP cleaned up the objects when a form was destroyed or the PRG ended. Is this a safe assumption or should I manually be cleaning things up?

In code like a PRG or a Method, you'll be fine as long as you aren't using PUBLIC variables (but then, your never fine if you ever use them :-), but if you ever assign an object to a form property, you must clean it up with o.Prop = .NULL., or you'll probably get a dngling object reference and stuff doesn't release right.
Previous
Reply
Map
View

Click here to load this message in the networking platform