Roobiq / RBQFetchedResultsController

Drop-in replacement for NSFetchedResultsController backed by Realm.
MIT License
476 stars 70 forks source link

Memory Management issue #45

Closed mhollis1980 closed 9 years ago

mhollis1980 commented 9 years ago

Hey,

I ran into a problem with memory management and using the FetchedResultsController. Below I've attached a class diagram showing how the classes are currently being constructed.

plantuml1734893313714000776

Looking at the diagram there is a retain cycle between the delegate proxy and the FetchedResultsController and one between the FetchedResultsController and my ViewController. This is causing all the objects in this graph to not be cleaned up after they're pushed off the navigation stack. Basically when I comment out self.viewModel.fetchResults.delegate = self all my classes get cleaned up.

I have been digging in the code and found that if changing the protocols to extend :class and change both delegate refs in DelegateProxy and FetchedResultsController to weak public var delegate: <Type>? all the objects get cleaned.

If I'm doing something wrong please let me know otherwise I can fork the code and make the changes if you feel this change is appropriate.

Thanks, Mike.