Message Sent to Deallocated Object
So, I have TPKeyboardAvoidingScrollviews in a couple nibs. I don't really reference them in the code so they usually don't have an IBOutlet at all.
I'm experiencing an issue where I'm getting the dreaded Message Sent to Deallocated Object crash. I can reliably reproduce this by going through my applciation to a certain point, hitting a button that triggers a popToRootViewControllerAnimated:NO. I can then go to a certain screen and reliably crash the application.
The crash occurs in UIScrollView+TPKeyboadAvoidingAdditions.h here:
- (UIView*)TPKeyboardAvoiding_findFirstResponderBeneathView:(UIView*)view {
// Search recursively for first responder
for ( UIView *childView in view.subviews ) {
if ( [childView respondsToSelector:@selector(isFirstResponder)] && [childView isFirstResponder] ) return childView;
UIView *result = [self TPKeyboardAvoiding_findFirstResponderBeneathView:childView];
if ( result ) return result;
}
return nil;
}
Heres some retain counts and the line it's dying on, spit out by the profiler:
Event Type ∆ RefCt RefCt Timestamp Responsible Library Responsible Caller
159 Retain +1 5 00:28.118.466 UIKit -[UINavigationController _startCustomTransition:]
161 Retain +1 5 00:28.179.409 libsystem_sim_blocks.dylib _Block_object_assign
162 Release -1 4 00:28.406.413 UIKit _wrapRunLoopWithAutoreleasePoolHandler
163 Retain +1 5 00:28.732.541 UIKit __49-[UINavigationController _startCustomTransition:]_block_invoke
165 Retain +1 5 00:28.732.602 UIKit -[UINavigationController navigationTransitionView:didEndTransition:fromView:toView:]
167 Release -1 3 00:28.732.634 UIKit __49-[UINavigationController _startCustomTransition:]_block_invoke
169 Release -1 1 00:28.732.819 UIKit __destroy_helper_block_119
170 Retain +1 2 00:32.284.697 UIKit -[UINavigationController popToViewController:transition:]
171 Retain +1 3 00:32.284.765 UIKit -[UIViewController removeChildViewController:]
172 Retain +1 4 00:32.284.766 UIKit -[UIViewController removeChildViewController:notifyDidMove:]
173 Release -1 3 00:32.284.779 UIKit -[UIViewController removeChildViewController:notifyDidMove:]
174 Release -1 2 00:32.284.780 UIKit -[UIViewController removeChildViewController:notifyDidMove:]
175 Release -1 1 00:32.284.785 UIKit -[UIViewController removeChildViewController:]
176 Retain +1 2 00:32.284.799 UIKit -[UINavigationController popToViewController:transition:]
177 Release -1 1 00:32.291.358 GraphicsServices GSEventRunModal
178 Release -1 0 00:32.291.894 GraphicsServices GSEventRunModal
179 Zombie -1 00:55.265.379 UIKit -[UIResponder(Internal) _responderWindow]
whatcha think? this issue is triggered by me calling becomeFirstResponder on a textview in viewDidAppear. It works fine unless I go through the application a little first. I dont understand where the hook is that could cause this... is there some way the lilbrary could be holding on to a reference to one of my VC's? Could it be related to the notifications that get observed for & posted?
thanks for the great library!
Hmm, interesting. What's the full stack trace at the time of the crash?

The AddCardDetailsViewController that you see here is the new view that has the textview that I'm calling becomeFirstResponder on. The whole Message sent to deallocated object is referencing a view that i popped and am not retaining any references to. The reference count chart that I put up top is to demonstrate that I'm really not keeping it around at all... I don't understand how that message is going to that thing.
at the time of the crash, this method
- (UIView*)TPKeyboardAvoiding_findFirstResponderBeneathView:(UIView*)view {
// Search recursively for first responder
for ( UIView *childView in view.subviews ) {
if ( [childView respondsToSelector:@selector(isFirstResponder)] && [childView isFirstResponder] ) return childView;
UIView *result = [self TPKeyboardAvoiding_findFirstResponderBeneathView:childView];
if ( result ) return result;
}
return nil;
}
has the following properties:
childView is a UITextField
view is a TPKeyboardAvoidingScrollView
self is a TPKeyboardAvoidingScrollview
also, just tested on iOS6.1 to compare and it does not occur. only seems to be on iOS7.
i deleted a previous comment to keep clarity here and try and make all of this a little more concise.
I've narrowed down the scenario to be:
iOS7/iOS7.1, not iOS6.1
push a view controller with a TPKeyboardAvoidingScrollView on it.
pop to previous view controller
try and show the keyboard by selecting any search bar or text view
the above crash will occur
I implemented next method in my category on TPAvoidingKeyboardScrollView:
-
(UIView *)TPKeyboardAvoiding_findFirstResponderBeneathView:(UIView *)view { for (UIView *childView in [view subviews]) { if ([childView isKindOfClass:[UIResponder class]] && [childView respondsToSelector:@selector(accessoryView)] && [childView isFirstResponder]) { return childView; }
UIView *result = [self TPKeyboardAvoiding_findFirstResponderBeneathView:childView]; if (result != nil) { return result; }}
return nil; }
It works for me.