José,
We can't know the difference between the first reference to an object and the Nth reference to it. If you are dealing with normal containership hierarchies VFP object destruction should work pretty well on it's own.
If your classes that are holding object references they clean up after themselves with code in their Destroy() method where they set all object references they hold to .null. it should solve most problems.
In the case where ObjectA has a reference to ObjectB and ObjectB holds a reference to ObjectA then you may need to resort to code like this:
if ( ! isnull( this.oReference ) )
this.oReference.ClearReferences()
this.oReference = .null.
endif
Where the ClearReferences() method sets all of it's object references to .null.
I had a situation once in a classlib documentation tool where several mulitple-linked lists maintained a web of crosslinks between each of the objects in memory. At destroy time there is no good way to completely follow each linked list to clear or do avoid recursion limits during Destroy(). So what I did was create a single-linked list allocation thread through every object and the ClearReferences looked like:
with this
.oParent = .null.
.oSibling = .null.
.oLeft = .null.
.oRight = .null.
endwith
And then starting from the root node
local loNode, loNext
loNode = this.oAllocation
do while ! isnull( loNode )
loNode.ClearReferences()
loNext = loNode.oAllocation
loNode.oAllocation = .null.
loNode = loNext
enddo
>Because in my enterprise have a project bad designed with very C5 candidates for bad object destruction, or better for object don´t released from memory.
>
>A "Analyst" desing a process for deleted all objects recursively, but he found circular references, and the solution done was to detect the first reference.
>
>I try to explain him what a reference is, only a pointer where the object is in memory, and then he can´t know where is the first or the second, but he say me to send the message...
>
>Thanks for your time, now he know this isn´t the solution to problem.