Would This Cause a Memory Leak?

I have a webpage with a button on it that will process data that takes a while to perform. We’ll say that the routine is called DoTediousWork

If you click that button, I have a webdialog that pops up and asks the user if they are certain they want to proceed because DoTediousWork may take a few moments.

If they select Yes, the web dialog will call DoTediousWork, a routine that is in the parent Web page. Then, the web dialog closes.

So, it is circular in the sense that a webpage invokes a dialog that then calls a routine in the parent page. But, is that the sort of thing that people refer to in the forums when they say avoid circular references?

I don’t think so. A circular reference is when object A holds a reference to object B, and object B holds a reference to object A. Because each hold a reference to the other, you can never get rid of those objects unless you manually clear the references.

Imagine it this way: You create a ParentObject with a property, Child that holds a ChildObject. In turn, the child stores its parent in it’s Parent property. You get to the child by going through the parent, so ParentObject.Child.

Now you’re done with the parent so you set the variable that holds it to nil, but Xojo does reference counting to see if an object is still active and it sees a reference to ParentObject in the Child.Parent property. Even though you’ve lost access to it, both the parent and child continue to exist and you’ve created a memory leak because they can’t go away.

HTH.

I see. I was afraid I had introduced a big no-no in my code when I read the posts mentioning circular references