1

I have an app that receives remote notifications. My view controller that is shown after push has a tableview. App crashes very randomly (1 in 20 tries) at line setting frame:

if (!myTableView) {
        NSLog(@"self.myTableView is nil");
    }
    myTableView.frame=CGRectMake(0, 70, 320, 376);

This only happens when i open the app, then open some other apps and then receive the push notification. I guess it has something to do with memory. I use ARC (ios 5). The strange thing is that nslog is not displayed, so tableview is not nil.

Crash log:

Exception Type:  EXC_BAD_ACCESS (SIGSEGV)
Exception Codes: KERN_INVALID_ADDRESS at 0x522d580c
Crashed Thread:  0

 Thread 0 name:  Dispatch queue: com.apple.main-thread
 Thread 0 Crashed:
 0   libobjc.A.dylib                0x352b1f7e objc_msgSend + 22
 1   Foundation                     0x37dc174c NSKVOPendingNotificationCreate + 216
 2   Foundation                     0x37dc1652 NSKeyValuePushPendingNotificationPerThread + 62
 3   Foundation                     0x37db3744 NSKeyValueWillChange + 408
 4   Foundation                     0x37d8a848 -[NSObject(NSKeyValueObserverNotification) willChangeValueForKey:] + 176
 5   Foundation                     0x37e0ca14 _NSSetPointValueAndNotify + 76
 6   UIKit                          0x312af25a -[UIScrollView(Static) _adjustContentOffsetIfNecessary] + 1890
 7   UIKit                          0x312cca54 -[UIScrollView setFrame:] + 548
 8   UIKit                          0x312cc802 -[UITableView setFrame:] + 182
 9   POViO                          0x000913cc -[FeedVC viewWillAppear:] (FeedVC.m:303)

Dealloc is not called because it is not logged:

- (void)dealloc {

NSLog(@"dealloc");

}
DixieFlatline
  • 7,895
  • 24
  • 95
  • 147
  • It would give me peace of mind to see the result of `if (nil != myTableView)` – Matt Sep 07 '12 at 09:10
  • Also, try turning on zombies as described here: http://stackoverflow.com/questions/5386160/how-to-enable-nszombie-in-xcode – Matt Sep 07 '12 at 09:13
  • myTableView is most likely deallocated – Andrey Chernukha Sep 07 '12 at 09:15
  • Have problems with turning on zombies, because to receive push notifications, it must be run with distribution profile so it cant be profiled with zombies. – DixieFlatline Sep 07 '12 at 09:19
  • App may crash randomly because of memory issues if you run it on iOS 4 and use ARC. Although ARC is not an option of OS but rather of compiler, it still doesn't work well on iOS 4. What is your iOS version? – Denis Kutlubaev Sep 07 '12 at 09:33
  • Try to put didReceiveMemoryWarning method and NSLog inside it. Assure that it is not called by absense of memory. I had random crashes, when memory was off, but I didn't know that, because Instruments seems to be not showing leaks on images. – Denis Kutlubaev Sep 07 '12 at 09:44
  • I am logging memory warnings. They dont appear. – DixieFlatline Sep 07 '12 at 10:28
  • The most relevant call to your code in the crash log is `9 POViO 0x000913cc -[FeedVC viewWillAppear:] (FeedVC.m:303)`. What codes do you have in `viewWillAppear:` method? – Sierra Alpha Sep 07 '12 at 15:06
  • Yes, this is where frame is set for tableview. – DixieFlatline Sep 07 '12 at 15:33
  • `SIGSEGV` means your are trying to access some part of the memory that is not accessible. If you look at the crash log, `[UITableView setFrame:]` is happening after call to `viewWillAppear`. So I think, that means there is no view at all, and naturally no tableView. Chances are your view is unloaded, and your are trying to access it and set a frame on one of its subviews.If your application is in the background and you get a push notification, before setting the frame, check if the app is active on the screen, then set the frame. – Sierra Alpha Sep 07 '12 at 15:45

3 Answers3

0

You are having memory issues. Your tableView is reaching a retain count of zero; so although a pointer to the tableView still exists, the system has trashed the object at that actual address, hence the EXC_BAD_ACCESS.

It's possible that your UI that showed the tableView is hidden and therefore unloaded, but you've left some logic that assumes the table view still exists when it doesn't.

It's hard to debug what's going on without seeing more of the project. The best thing for you to do is have a careful look at the design of your application and UI flow. What would be causing the UI to be be released? How are you entering the code that assumes that part of the UI is still there?

N.B. Sending messages to a nil reference would not generate any errors; this is by language design.

occulus
  • 16,959
  • 6
  • 53
  • 76
  • I also tried defining tableview as @property (nonatomic, retain) myTableView, but the result was the same. – DixieFlatline Sep 07 '12 at 09:43
  • If you're using ARC, then you shouldn't write retain as part of a property declaration. 'strong' is the word to use. However, it's the default, so if you miss out both strong and weak, it will end up being strong. – occulus Sep 07 '12 at 15:38
0

I found the solution here: Using ARC and UITableViewController is throwing Observation info was leaked, and may even become mistakenly attached to some other object

Seems pull to refresh (subview to tableview) was causing problems.

Community
  • 1
  • 1
DixieFlatline
  • 7,895
  • 24
  • 95
  • 147
-1

Do not change frame directly,do something like this.

CGRect frame = self. myTableView.frame;
frame.x =something;
frame.y=something;
myTableView.frame=frame;

and let me know.

Sanoj Kashyap
  • 5,020
  • 4
  • 49
  • 75