Question Circular object references

TomBlue999

New Member
I'm having an issue with object references and garbage collection. Maybe I'm doing something completely wrong or there is any best practice I did not find.

Simplified, I have 2 classes where one is instantiiating the other, let's call Parent and Child. Because I need access to some public properties of the parent object within the cild object I'm instantiiating the child object with a reference to to the parent object. Here's a simplified code example:

Code:
class Parent:
    constructor Parent ():
        this-object:pChild = new Child(this-object).
    end constructor.
 
    def private property pChild as Child no-undo
        get.
        set.
 
    def public property pParentProp as char no-undo
        get.
        set.
end class.
 
class Child:
    constructor Child (clsParent as Parent):
        this-object:pParent = clsParent.
    end constructor.
 
    def public property pParent as Parent no-undo
        get.
        protected set.
 
    method private DoAnything ():
        def var test as char no-undo.
        test = pParent:pParentProp.
    end method.
end class.

But with that I have a big issue with garbage collection. Because Parent object is referencing Child object and vice versa the automatic garbage collection is not working anymore. Additionally the objects remain in memory if I try delete the Cild object manually in destructor of the parent object.

How do you handle access to properties and methods of parent objects within an child object without running into theses issues with garbage collection?
 

TomBlue999

New Member
Hi tamhas!

Thank's for your message!
But, I don't see why you would have a problem cleaning up manually.

Because it is not working under any cirumstances. With the simple example above, yes, your're right! But if I use Client.cls from my example above and add the instances to some kind of list object (like provided at http://www.oehive.org/CollectionClasses) than the manual cleanup ist not working anymore. Even if adding a loop in the List.cls and deleting any instance of the temp-table record manually within the destructor of the List class. I've written a similar list class which uses an extent instead of the temp-table, there I have the same problem.

I'm working on a simplified example to post here.

Cheers
Thomas
 

tamhas

ProgressTalk.com Sponsor
Have you tried following this through on the debugger? It sounds like you are failing to get it out of the collection and, of course, it is not going to go away then.
 

TomBlue999

New Member
No, not yet. What should I look at in debugger? I have simplified the problem so that I do not think that there's a specific bug causing that. Anyway, I'm not familiar with the debugger, yet, but will give it a try. Thx
 

tamhas

ProgressTalk.com Sponsor
You should also look into the log-manager. It is documented in the Debugging and Troubleshooting manual. It has a bunch of flags to trace what happens in a session, including object creation and deletion. I don't use the debugger much myself because I think that a well-written piece of code should tell one where the error has to be without having to do that kind of probing. I have found the log-manager handy since one can write out messages and follow different kinds of events. While there is a known issue with certain kinds of circular references and garbage collection, I have never seen a case where one couldn't delete the object directly. The key is defining who and when makes that decision. Usually, this is "you make it; you delete it", but there are exceptions.
 
Top