Skip to content
This repository has been archived by the owner on Oct 31, 2019. It is now read-only.

Memory keep growing #38

Open
allenwang162 opened this issue Apr 27, 2014 · 6 comments
Open

Memory keep growing #38

allenwang162 opened this issue Apr 27, 2014 · 6 comments

Comments

@allenwang162
Copy link

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
screen shot 2014-04-26 at 9 20 39 pm

Allen

@Morkrom
Copy link

Morkrom commented Aug 4, 2014

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.

@lukescott
Copy link
Owner

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.

@donaldkwong
Copy link

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.

@lukescott
Copy link
Owner

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.

@donaldkwong
Copy link

With the subclass approach, the KVO is not needed at all. You can simply reimplement setCollectionViewLayout and add the logic there.

@liuxuan30
Copy link

have this been solved?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants