Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
NewObject or CreateObject or AddObject
Message
General information
Forum:
Visual FoxPro
Category:
Object Oriented Programming
Environment versions
Visual FoxPro:
VFP 8 SP1
Miscellaneous
Thread ID:
01250745
Message ID:
01251229
Views:
15
Thanks Naomi,

I've used some of what Christof suggests, but the problem with all of this is that it's really expensive in terms of resource usage. And you still have to 'register' objects in some special way.

What I do is have an Initialize() and Dispose() method on my objects where any cleaned up resources are declared in Initialized and cleaned up in Dispose(). Dispose() is called from Destroy automatically or can be explicitly invoked and Initialize() automatially from Init() (by default).

It works and it's reliable without extra overhead but it does require some discipline. The more I use this approach the more sense this makes though.

I suppose this could even be automated more by adding references to a structure (array/collection) and then automatically going through through from Dispose(). But that doesn't actually save much and again adds some overhead and requires a specific subclass.

+++ Rick ---

\
>>Hi Marcia,
>>
>>>As a generally rule, I use Composition ( AddObject ) rather than Aggregation ( NewObject or CreateObject ) whenever possible because the container object "owns" all of the contained items. When the container is destroyed, all of its contained objects are destroyed too. So the chances of a dangling reference are greatly reduced.
>>
>>The only reason this matters is because of VFP's buggy garbage collector <s>. AFAIK child object references are still released before the Destroy() of the parent object fires so the difference between a container and an actual object reference doesn't make that much of a difference. Certainly it's easy to have a dangling reference that won't clean up either way...
>>
>>The key issue for this often is order of how objects are released and the only real safe way is to explicitly release the objects. In Web COnnection 5.0 for example I've had major issues with this very issue and I experimented around with different classes, containership etc. before just using Custom classes and properties, but firing an explicit Dispose() method whenever objects release with that method implementing the required release sequence. It works, but of course requires that control developers pay close attention to implementing a Dispose() method properly.
>>
>>+++ Rick ---
>
>Hi Rick,
>
>You may check Re: Automatic Destroy method Thread #1246863 Message #1247285
+++ Rick ---

West Wind Technologies
Maui, Hawaii

west-wind.com/
West Wind Message Board
Rick's Web Log
Markdown Monster
---
Making waves on the Web

Where do you want to surf today?
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform