Closing circle references


in an old project (webapp), which I developed when I was new to xojo, I wrote some code with circle references.

My questions:

  1. how can I easily detect circle references?
  2. how can I avoid or remove circle references without the need to rewrite big parts of my code?

Thanks :slight_smile:

Use weakRefs?

Never worked with.

How can I transform a property, which holds a circle reference into a weak ref?

One easy way is to use Computed Properities. Lets say you had a property named Parent as Session

  1. Right click and convert it. It’ll create a new private property named mParent and a getter/setter pair where the property was.
  2. Change mParent type to WeakRef.
  3. In the Setter change the code to “mParent = new WeakRef(value)”.
  4. In the Getter use this:

if mParent = Nil or mParent.value = Nil then Return Nil Else Return Session(mParent.Value) End if

Once you’ve done this, you’ll also need to protect your code against this property returning Nil if the Session has gone away, whether by checking for Nil or using exception handling.