samvermette / SVPullToRefresh

Give pull-to-refresh & infinite scrolling to any UIScrollView with 1 line of code.
http://samvermette.com/314
MIT License
4.82k stars 1.09k forks source link

observer leak #222

Open bestwnh opened 10 years ago

bestwnh commented 10 years ago

I just use the PullToRefresh and InfiniteScrolling just like normal in code. But in one of my view controller the Xcode tell me the observer not remove when the scrollview dealloc. It not crash but may make a leak. And all other view controller is working so good. It's weird.

But I finally find the issue.:tada::tada::tada: When I set the showsInfiniteScrolling = YES or showsPullToRefresh = YES before addPullToRefreshWithActionHandler or addInfiniteScrollingWithActionHandler the scrollview will add observer twice and only remove once when it dealloc.

Because the condition in setShowsPullToRefreshandsetShowsInfiniteScrolling is like this if (!self.pullToRefreshView.isObserving) { if (!self.infiniteScrollingView.isObserving) { Before you set the handler the pullToRefreshViewandinfiniteScrollingView is nil so the code run inside.

I already fix it and pull a request: https://github.com/samvermette/SVPullToRefresh/pull/221