PullToRefreshView icon indicating copy to clipboard operation
PullToRefreshView copied to clipboard

Big issue when receive memory warning and implement viewDidUnload

Open JmeHsieh opened this issue 14 years ago • 9 comments

I can't release pullView in viewDidUnload. App will CRASH if it receive memory warning.

JmeHsieh avatar Sep 06 '11 18:09 JmeHsieh

Not nearly enough detail. Closed for now.

grp avatar Sep 28 '11 01:09 grp

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.

JmeHsieh avatar Sep 29 '11 10:09 JmeHsieh

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>
)

maddox avatar Jan 28 '12 03:01 maddox

Actually, I don't think that resolved the crasher either.

maddox avatar Jan 28 '12 03:01 maddox

hwhoops. Didn't see this:

- (void)containingViewDidUnload;

Call this in viewDidUnload and dealloc and you're good to go.

maddox avatar Jan 28 '12 03:01 maddox

This seems like it's still an open issue right?

drewish avatar Jul 14 '12 22:07 drewish

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?

grp avatar Jul 29 '12 23:07 grp

Looks like I don't remember my own code. :) I'll take a look at this when I get a chance.

grp avatar Jul 29 '12 23:07 grp

@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.

cbowns avatar Jul 31 '12 22:07 cbowns