views:

173

answers:

2

I wrote a small application using iPhone 3.x sdk. The app works well on device/simulator 3.x. But when I switch to device/simulator 4, it exit directly when I navigate among the tab pages. Here is the log form ~/Library/Logs/CrashReporter,

Exception Type: EXC_BAD_ACCESS (SIGBUS) Exception Codes: KERN_PROTECTION_FAILURE at 0x0000000000000003 Crashed Thread: 0 Dispatch queue: com.apple.main-thread

Application Specific Information: objc_msgSend() selector name: isKindOfClass: iPhone Simulator 4.0 (211.1), iPhone OS 4.0.2 (iPhone/8A400a)

Thread 0 Crashed: Dispatch queue: com.apple.main-thread 0 libobjc.A.dylib 0x02502a97 objc_msgSend + 27 1 UIKit 0x00303f20 -[UIView(Internal) _didMoveFromWindow:toWindow:] + 955

Could you please give me some help, thanks in advance.

Linkou Bian Email/MSN: [email protected]

+3  A: 

I wrote this blog to help understand and debug EXC_BAD_ACCESS

Basically, you are dereferencing a pointer that is pointing to memory that isn't allocated to your process. The main reasons that this could happen are

  1. You are using an object that has been deallocated
  2. The heap is corrupt

The things you should do to debug this:

  1. Do a Build and Analyze. The reports of leaks are bad, but not related to this issue -- you want to look for issues of too few retains

  2. Turn on Zombies and run in the debugger. Now, none of your objects will be deallocated, but when they have a retain count 0, they will complain to the debugger if you use them.

There are other tips on the blog that are a little harder to explain

Lou Franco
Lou, very helpful. Thanks a lot. The issue is due to an object is released incorrectly. It is created by the factory method, and I shouldn't release it manually. But the key point is, why it works well on 3.x? Does it mean, iOS 4 does better in memory management, the new OS helps me find some potential bugs.
Linkou Bian
It's just random. It was going to crash at some point on 3.x too. You can dereference a bad pointer as long as the memory is mapped to your process and it won't cause EXC_BAD_ACCESS (it's still a bug -- it will probably corrupt memory). You want EXC_BAD_ACCESS to happen as soon after the bug as possible -- it helps detect the bug, but if it doesn't happen, it doesn't mean the bug isn't there.
Lou Franco
Agree. Can Instrument help find these issues in advance? I didn't try with that tool. Or is there any useful tool help us detect EXC_BAD_ACCESS earlier?
Linkou Bian
Nothing for sure. You can Enable Guard Malloc and turn on a more sensitive heap by following directions under Detecting Heap Corruption http://developer.apple.com/iphone/library/documentation/Performance/Conceptual/ManagingMemory/Articles/MallocDebug.html
Lou Franco
This post is very cool in my opinion. Share with you, http://www.markj.net/iphone-memory-debug-nszombie/
Linkou Bian
A: 

Hi

i am developed VUmeter functionality with live radio streaming. it's working well when i run into simulator version 4.0 but in device(3GS,4.0) its not working i am not getting updated values of audiolevels. suppose at first time when method call i got value levels: 0.001817, peakLevels: 0.005463 its remain same not changed whereas in simulator same code working well.

levels[0]        = self.audioLevels[0].mAveragePower ;
peakLevels[0]    = self.audioLevels[0].mPeakPower ;   

suggestion or advice require...

uday