-
Notifications
You must be signed in to change notification settings - Fork 175
Memory keep growing #38
Comments
Have the same issue. [[LSCollectionViewHelper alloc] initWithCollectionView:self]; is retaining the collection view. Have tried making _collectionView in LSCollectionViewHelper weak. It almost works except there's a crash with the observer in LSCollectionViewHelper, removing the observer does not simply work. |
This is definitely a retain cycle. @Morkrom It looks like you were on the right track. In theory the helper should be collected along with the collection view given the object association. The helper should be collected first because the collection view owns the helper. Removing the observer in the helper's dealloc should work. If for some reason the collection view is being collected first, that would explain the crash. |
The UICollectionView instance is deallocated first, which is causing an exception to be thrown because the _collectionView ivar is already nil when the removeObserver is attempted, so the removeObserver doesn't actually do anything. |
Probably the best solution is to throw out the category in favor of a subclass. I actually did that in the experimental branch, but it's vastly different than what's on master (actually contains both version of the code). I was attempting to take a different approach, but I haven't had time to finish it due to lack of time. With the subclass approach the object association function calls would go away and the helper would be referenced as a subclass property. This would allow you to safely remove the observer in the dealloc. |
With the subclass approach, the KVO is not needed at all. You can simply reimplement setCollectionViewLayout and add the logic there. |
have this been solved? |
I really love this library,thank you!
I have a concern about one issue (I did see my app crashed because of it) . please help.
--here is how I reproduced it.--
I modified FlowLayoutDemo project and created a new UIViewController( and Converted to UINavigationController) in it.
I placed a single button from the new UIViewController to invoke (push segue) the Draggable UICollectionView, it will increase about 2MB every time when I click the push button.(then I click Back button & push it again ). It seems every time it will call - (LSCollectionViewHelper *)getHelper to init a new helper that keep the memory growing. All previous memory still retained by some reason .
Any idea about how to solve this issue?
Thanks
Allen
The text was updated successfully, but these errors were encountered: