Alternative/Simulation of an array of pointers


I’ve found myself in the situation where I have a class that needs to keep track of an array of another class but not… directly. Really an array of pointers is exactly what I require because if the value in the array changes somehow then I want that change to be reflected.

For example:

If I have 3 Windows and each window has an apple in it, then I have a manager class that knows in each of these windows there is an apple. I cannot simply say:

dim apples(3) as apple apples(0) = apples(1) = apples(2) =

That won’t work, because it creates a copy of the apples. Now the Windows have 3 apples, and the manager has 3 apples too. If Window1’s apple gets eaten by a worm and destroyed, then that has nothing to do with the manager’s first apple because it isn’t the same apple.

I don’t want the manager to have three of his own apples, I want him to have a list of the apples that belong to the windows. He should have NO apples.

Does anyone have a solution?

Maybe an array of WeakRefs? A WeakRef holds a reference to an object without incrementing the object’s reference count. If the object is destroyed, the WeakRef will refer to Nil.

It works, thanks.