Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
RemoveObject and Release
Message
From
14/07/1999 23:59:05
 
 
To
14/07/1999 22:53:19
Stephen Bridgett
Stephen Bridgett Consulting
Gloucester, Ontario, Canada
General information
Forum:
Visual FoxPro
Category:
Object Oriented Programming
Miscellaneous
Thread ID:
00241632
Message ID:
00241647
Views:
12
For each AddObject, a RemoveObject must be called. You don't need to do this explicitly, VFP will do it. For objects created with CreateObject: you can destroy them in several ways, but the best one is to break all links to that object (VFP will destroy the object then).

If you have bidirectional ownership relations A <-> B, it's better to break both links. Basically, for each has-a relation you create, you must take care to break it too. VFP will often fail to release objects simply because there are other still valid references to them. Bidirectional links (or more generic, circuit links) are a sure source of problems if they are not treated correctly/carefully.

My advice: review your design and look for a solution without such links... if possible. I don't want to say that your solution is not good. It may be the best one for your problem. But you must be careful and it may mean more effort than necessary (especially because the bugs you may encounter are usually very difficult).

Vlad

>1. If I use RemoveObject in the outside parent container and remove the contained objects, is the memory freed up. In other words, does Fox do the garbage collection on the CREATE(D)OBJECTS.

Yes, as long there are no more references to those objects.

>2. Do I have to break the backlinks before I can release objects.

Yes.

>3. What is the essential difference between RemoveObject and Release.

RemoveObject removes objects from containers, objects that were created using AddObject. RELEASE destroys variables. If a variable holds a reference to an object and there are no other references to that object, the object is destroyed when you RELEASE the variable.

>This is a thorny issue. If you play with this stuff it quickly yields inconclusive results. Except of course, if you do break rules, eventually the app crashes.

Right. :)

Vlad
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform