I'm implementing a UITableView as a first level view controller that contains 5 table cells. Hitting on any of these cells will present a second level view. At the top left of this level view, there is a "back" button to return to the first level view. At the second level view, swiping left or right will show adjacent views continuously that link to those adjacent table cells at the first level view.
After running, from first level view to second level view it's ok. But when hitting the "back" button, going back to first level view from second level view, the following is the issue I got.
An instance 0x7a8f130 of class UIScrollView 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: 0x9149570>
)
I found
- (void)viewDidUnload
{
[super viewDidUnload];
[self.scrollView removeObserver:self forKeyPath:@"frame"];
[self.scrollView removeFromSuperview];
_scrollView = nil;
}
in the GDIInfinitePageScrollViewController.m
that I'm using to implement an infinite scroll view controller. When I commented this out, the issue is still there.
when I set breakpoint NSKVODeallocateBreak
, here is what I got
0x1170ae0: pushl %ebp
but I have no idea about what it means.
Does anyone know how to fix this issue?
The reason you are getting that message is because the UIScrollView instance is being released before its observers are removed.
The method -(void) viewDidUnload is called when the view has already been released, so that call to remove the observer is too late. In addition, this has been deprecated with iOS 6, along with -(void) viewWillUnload.
As an alternative, try removing the observer when hitting the back button.