I have a class, MyObjectClass with a property, MyReport of type MyReportClass.
I have a Report class called, MyReportClass with a property, MyObject of type MyObjectClass.
MyObjectClass has a method called MakeReport:
[code] If MyReport = Nil then
MyReport = New MyReportClass(me)
End if[/code]
This gives me a circular reference.
MyObjectClass is stored in the RowTag of a listbox.
If rows in the listbox never get removed for the life of the app, do I need to be concerned about the circular reference?
Thanks guys. The wording of the first article I posted, tripped me up on typing the properties. Specifically, “The private property created by Xojo now changes type to WeakRef.” The private property needs to be changed manually and the original property stays as declared.
One suggestion that wasn’t in my original post: use computed properties to manage the WeakRefs for you.
Create a computed property, MyParent As ParentClass
Create a shadow property, mMyParentWR As WeakRef
Use the MyParent getter and setter to translate to and from the WeakRef.
In this way, you can just reference MyParent without worrying about the accompanying processing. Just be prepared for MyParent to be nil.
Get
if mMyParentWR is nil then
return nil
else
return ParentClass( mMyParentWR.Value )
end if
Set
if value is nil then
mMyParentWR = nil
else
mMyParentWR = new WeakRef( value )
end if