How to avoid retain cycles if a protocol cannot be class?

Hi


I just debugged a memory leak by making some of my protocols "class" and making the variables of that type weak.
But what would i have been able to do if the project had a mix of structs and classes that implemented those protocols and I was not able to mark the protocol weak, but had to have a potential retain-cycle with a class?

No simple ways. You may need to check and modify all the types conforming to the protocol. Please show all of them.

It just feels like a perhaps inevitable way for this to be implemented. To get around it, I suppose I could have a generic class that serves as a wrapper round the protocol and I could use a weak var of that.

I suppose I could have a generic class that serves as a wrapper round the protocol and I could use a weak var of that.


That sounds to be a good way. And may be a better way when the types cannot be limited in a small set.

How to avoid retain cycles if a protocol cannot be class?
 
 
Q