Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Big issue when receive memory warning and implement viewDidUnload #6

Open
JmeHsieh opened this issue Sep 6, 2011 · 9 comments
Open

Comments

@JmeHsieh
Copy link

JmeHsieh commented Sep 6, 2011

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

@grp
Copy link
Owner

grp commented Sep 28, 2011

Not nearly enough detail. Closed for now.

@grp grp closed this as completed Sep 28, 2011
@JmeHsieh
Copy link
Author

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.

@maddox
Copy link

maddox commented Jan 28, 2012

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
Copy link

maddox commented Jan 28, 2012

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

@maddox
Copy link

maddox commented Jan 28, 2012

hwhoops. Didn't see this:

- (void)containingViewDidUnload;

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

@drewish
Copy link

drewish commented Jul 14, 2012

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

@grp
Copy link
Owner

grp commented Jul 29, 2012

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 grp reopened this Jul 29, 2012
@grp
Copy link
Owner

grp commented Jul 29, 2012

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

@cbowns
Copy link
Contributor

cbowns commented Jul 31, 2012

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

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

No branches or pull requests

5 participants