Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Cleaning up object references
Message
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00167010
Message ID:
00167013
Views:
30
Paul,

Depending on the types of objects you are using you might be better off with an object containership:

this.AddObject( "oSecond", "SecondObj" )

When you Release() the outer object the inner one will automatically release. The oSecond can use this.parent to reference the outer object.

If containership isn't possible and you really do want to "sibling" objects to have links to each other it gets a little more complicated. Especially if either one can release first which can invalidate the other object's reference to it. I've used an oOther.Register( this, REGISTER | UNREGISTER ) method so that you can tell the other object to set or clear the reference. Init():

this.oOther = CreateObject( "Other" )
this.oOther.Register( this, REGISTER )

and the Destroy() looks like:
if ( IsObject( this.oOther ) )
   this.oOther.Register( this, UNREGISTER )
   this.oOther = .null.
endif
In the Destroy() you definately need to set the this.oReference=.null. so that you don't leave dangling references which will prevent objects from releasing. There is a tool on my website to help track object refs. CLEAR ALL can usually help while you are getting the code working.

There are some other design patterns dealing with inter-object communication that you might want to take a look at.

>I'm starting to write more apps. using objects instead of functions/procedures. In a current app, almost everything is an object, and there isn't a user interface (except for a diagnostic screen that can be turned on/off in the configuration program). As I'm writing this, I'm starting to realize I don't understand where/how to release all of my objects to clean up things. Here's how the program currently works:
>
>main.prg - creates main object
>
>mainobj - creates two different objects it uses for processing. If the debug mode is on, it also creates a dianostic screen where messages appear as things are processed. All the objects maintain references to the other objects, for example:
>
>In my MainObj:
>THIS.oSecond = CreateObject("SecondObj")
>THIS.oSecond.oMainObj = THIS
>
> I'm trying to do two different things. If the diagnostic screen is running, if I close it I want all the other objects/programs to quit. I'm also thinking about file-based messaging to be able to close this app if the diagnostic screen isn't running. Right now, I've tried a bunch of combinations of things to release these objects, but I'm fairly sure they aren't working (since after "closing" the app, I can't edit it in VFP because VFP says it's in use).
df (was a 10 time MVP)

df FoxPro website
FoxPro Wiki site online, editable knowledgebase
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform