Memory reference that does not stop garbage collection.

Jonathan Levi catanscout at
Fri Feb 8 15:42:13 UTC 2019

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 = [];

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

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 


More information about the Digitalmars-d-learn mailing list