NSZombieEnabled does not work

2019-01-23 05:09发布

When I set NSZombieEnabled = Yes nothing is written to the console. How can I fix this? Or can you advise me any other tools for an EXC_BAD_ACCESS?

8条回答
▲ chillily
2楼-- · 2019-01-23 05:14

I think Not every EXC_BAD_ACCESS is found by NSZombie Enabling..
Because Some cases I am also not getting result while using zombie..
I think only EXC_BAD_ACCESS related to the use of released object can view by enabling zombie.

And one more issue I noted while using zombie is : Sometimes It also cause crashes on debug. One case I caught crashed, showing :
*** -[MagazineWebview respondsToSelector:]: message sent to deallocated instance 0x58ce2a0
It happens only on when enabling NSZombie.

What I am doing is, On
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
I release the current "MagazineWebview" object and load the given [request URL] in another "MagazineWebview" object. For Achiving my some functionalities...

thanks

查看更多
ら.Afraid
3楼-- · 2019-01-23 05:16

Also make sure you initialize all pointers to nil before using them!

If you use a pointer without initializing it to nil or any other object, you are propably going to end up accessing memory which isn't yours.

For example the following code will also give an EXC_BAD_ACCESS which is not traceable using the NSZombieEnabled flag caused by the last line.

RecordingLocation* closest;

//find the closest recording location
for (...)
{
    //try to find the closest object...
    //suppose we don't find anything so closest is never set.
}

if (closest!=nil)
    NSLog(@"Closest: %f,%f",closest.x,closest.y);
查看更多
女痞
4楼-- · 2019-01-23 05:18

Is you search Stack Overflow for EXC_BAD_ACCESS, you'll find a number of people with the same problem that you have. The vast majority of the time that you hit this, you are encountering memory issues. If you are following the protocol described here or here, and you're not seeing any reports of messages being sent to released objects on the console, it might be something different.

Have you tried starting the application in the debugger (Run | Debug - Breakpoints On)? As soon as you hit the EXC_BAD_ACCESS, the debugger should halt. If you look at the backtrace displayed in the debugger (Run | Debugger), it might show you where the error occurred.

查看更多
\"骚年 ilove
5楼-- · 2019-01-23 05:19

I had a different experience with EXC_BAD_ACCESS, so I would like to share.

As stated in the questions, even though NSZombieEnabled was checked, nothing was written to the console. After several hours of struggling in the simulator, I decided to install it to the device. The error message that I got from debugging with the device was more helpful.

Eventually, I noticed that I was getting EXC_BAD_ACCESS error and strange behavior because I renamed a couple of xib files a day before. I selected the 'View Controller' object for MainWindow.xib file and corrected the NIB Name property. Then, everything worked smoothly.

查看更多
劫难
6楼-- · 2019-01-23 05:25

i don't understand how the answer to this question really answers the question..

i am asking myself the same thing. using xcode4 i have enabled NSZobmieEnabled = YES to halt when i access an object that has been released, instead of crashing with EXC_BAD_ACCESS - which is very helpful.

the question at hand was:

"When I set NSZombieEnabled = Yes nothing is written to the console. How can I fix this...".

simple and straight forward.

i am experiencing the same issue. xcode halts with the debugger but the console does not produce any message. i would expect something along the lines of:

"message sent to deallocated instance...".

查看更多
可以哭但决不认输i
7楼-- · 2019-01-23 05:25

As I just spent a happy 20 minutes staring at this with NSZombieEnabled not working, I thought I'd add this will cause a EXC_BAD_ACCESS

NSArray *arr = [NSArray arrayWithObjects:@"@dog","@cat",nil];

Note the missing '@' on the second param. I didn't :-)

查看更多
登录 后发表回答