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:
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?
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?