I have observers and listeners.

class Observer {
   Listener[] listeners;
}
class Listener {}

The observers keep references to listeners, but I would like the GC to garbage collect listeners even if observers have references to it and remove the references in observers.

I should be able to use `core.memory.GC.removeRange` right?

class Observer {
  Listener[] listeners;
  this() {
    listeners = [];
    GC.removeRange(listeners.ptr);
  }
}

And in the deconstructor for listeners release the references in observers. How does that work if the listeners array gets reallocated when extending, do I just recall `removeRange` any time after an append?

I am guessing I am not the first one to want this so I would rather not reinvent the wheel myself. I also do not want memory leaks.

Thanks!

Reply via email to