Big issue when receive memory warning and implement viewDidUnload
I can't release pullView in viewDidUnload. App will CRASH if it receive memory warning.
Not nearly enough detail. Closed for now.
Just try to use your PullToRefreshView in viewDidLoad, and set to nil in viewDidUnload. Since PullToRefreshView is added as a observer of scrollView, while receiving memory warning, the scrollView is now being released. However, PullToRefreshView is still an observer of scrollView, which was just been released, now the app crash. This is the "Big Issue" that I can't release PullToRefreshView in viewDidUnload since the statements above.
This is confirmed. Except it's 2 different issues.
I don't see it in the code, but somehow, the delegate is being retained. This is what causes the crash.
Setting the pullToRefreshView's delegate to nil before nillng out the pullToRefreshView does in fact prevent a crasher. But the issue with the observer is still present.
Here is the warning:
2012-01-27 22:02:02.317 GHTeam[10054:15803] Received memory warning.
2012-01-27 22:02:02.318 GHTeam[10054:15803] An instance 0x904a800 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:
<NSKeyValueObservationInfo 0xa891080> (
<NSKeyValueObservance 0xa890d00: Observer: 0xa890ef0, Key path: contentOffset, Options: <New:
YES, Old: NO, Prior: NO> Context: 0x0, Property: 0xa891100>
)
Actually, I don't think that resolved the crasher either.
hwhoops. Didn't see this:
- (void)containingViewDidUnload;
Call this in viewDidUnload and dealloc and you're good to go.
This seems like it's still an open issue right?
I'm still not sure I understand. If you release your scroll view in -viewDidUnload, you should just release the pull to refresh view as well. Then it will remove its KVO context, and everything will be fine?
Looks like I don't remember my own code. :) I'll take a look at this when I get a chance.
@maddox has the right approach. I put in containingViewDidUnload as a safe way to break the KVO/view retain cycle here. It’s what Batch used to safely release the view.