samvermette/SVPullToRefresh — pull request #74 by fengjian0106 (2012-10-31 06:53:29+00:00)
Title: fix bug with "retain cycle" memory issues and remove KVO observer

hi samvermette, I like SVPullToRefresh, the design of it's public api is very cool. But there is some memory issues both in SVPullToRefresh and the Demo. The bug is "retain cycle", I suggest reading http://stackoverflow.com/questions/7853915/how-do-i-avoid-capturing-self-in-blocks-when-implementing-an-api

And I try to fix the bug, description as follows
1 Add SVRootViewController and UINavigationController and three "- (void)dealloc" to show the retain cycle memory leak. And use __weak/weak to fix the bug. Also can use instruments to see the memory bug

2 In SVPullToRefresh, the UIScrollView has add a KVO observer, but when the UIScrollView dealloc, it doesn't remove the observer. Also, it seems that the UIScrollView has no way to remove the observer elegantly without change the public api. I fix the bug with some trick, maybe not elegant, but it does can work -- I remove the observer in the "willMoveToSuperview" func of SVPullToRefreshView. ##The same bug with SVInfiniteScrolling.

hi samvermette, I like SVPullToRefresh, the design of it's public api is very cool. But there is some memory issues both in SVPullToRefresh and the Demo. The bug is "retain cycle", I suggest reading http://stackoverflow.com/questions/7853915/how-do-i-avoid-capturing-self-in-blocks-when-implementing-an-api

And I try to fix the bug, description as follows
1 Add SVRootViewController and UINavigationController and three "- (void)dealloc" to show the retain cycle memory leak. And use __weak/weak to fix the bug. Also can use instruments to see the memory bug

2 In SVPullToRefresh, the UIScrollView has add a KVO observer, but when the UIScrollView dealloc, it doesn't remove the observer. Also, it seems that the UIScrollView has no way to remove the observer elegantly without change the public api. I fix the bug with some trick, maybe not elegant, but it does can work -- I remove the observer in the "willMoveToSuperview" func of SVPullToRefreshView. ##The same bug with SVInfiniteScrolling.

Wth the original bug, the console will show some warning info like below :
2012-10-31 14:07:41.668 SVPullToRefreshDemo[5007:c07] An instance 0x99aa400 of class UITableView was deallocated while key value observers were still registered with it. Observation info was leaked, and may even become mistakenly attached to some other object. Set a breakpoint on NSKVODeallocateBreak to stop here in the debugger. Here's the current observation info:
(
Context: 0x0, Property: 0x8921a50>
Context: 0x0, Property: 0x89237a0>
Context: 0x0, Property: 0x8921a50>
Context: 0x0, Property: 0x8924900>
)