简体   繁体   English

调试Iphone程序收到信号:“ EXC_BAD_ACCESS”

[英]Debug Iphone Program received signal: “EXC_BAD_ACCESS”

i searched and tried a lot. 我搜索并尝试了很多。 But i really have no idea how to solve this – Thanks for your help 但是我真的不知道该如何解决– 感谢您的帮助

The Error-MSG: 错误消息:

Program received signal:  “EXC_BAD_ACCESS”.

The Line throwing the MSG 生产线投掷味精

log(sos_Trace, @"sendMail");

Important 重要

I make use of this logging-lib: http://code.google.com/p/soslog-objc/ 我使用了以下日志记录库: http : //code.google.com/p/soslog-objc/

Full SourceFile 完整的源文件

#import "ContactViewController.h"
#import "SOSLog.h"

@implementation ContactViewController

@synthesize mailButton, delegate;

- (void)viewDidLoad {  
    self.view.backgroundColor = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:@"bg_tile.gif"]];  
    [super viewDidLoad];  
}  

- (IBAction)sendMail:(id)sender {
    NSLog(@"sendMail");
    log(sos_Trace, @"sendMail");

    [delegate mail:self];
}

- (void)dealloc {
    [self.mailButton release];
    self.delegate = nil;
    [super dealloc];
}

@end

Having a look at the source for the SOS logging framework, log(sos_Trace, @"sendMail"); 看一下SOS日志记录框架的源代码log(sos_Trace, @"sendMail"); cannot possibly be the source of the crash unless you have code elsewhere that is corrupting the internals of the logging infrastructure. 除非您在别处有破坏日志记录基础结构内部的代码, 否则崩溃的根源不可能。

Post the full stacktrace of the crash. 发布崩溃的完整堆栈跟踪。

As @benzado noted, you have some bugs in your memory management code. 正如@benzado指出的那样,您的内存管理代码中有一些错误。 Fix those, too. 修复那些。 I would suggest running the static analyzer over your code and fixing anything it finds. 我建议对代码运行静态分析器,并修复发现的任何内容。 shift-cmd-A in Xcode should do the trick. Xcode中的shift-cmd-A应该可以解决问题。

Also, if you want to log when a method is called, this will work in any method : 另外,如果要记录调用方法的时间,则可以在任何方法中使用

log(sos_Trace, NSStringFromSelector(_cmd));

Or: 要么:

NSLog(@"[%@ %@] -- your message here", NSStringFromClass([self class]), NSStringFromSelector(_cmd));

I've not used the soslog framework before, so I can't offer any insight there. 我以前没有使用过soslog框架,因此在此我无法提供任何见解。 However, EXC_BAD_ACCESS is frequently caused by trying to access an object that's either been dealloc'd, or never initialized to begin with. 但是,EXC_BAD_ACCESS通常是由于尝试访问已取消分配或从未初始化过的对象而引起的。 Has sos_Trace been set up before you call it? 在调用它之前是否已设置sos_Trace?

EXC_BAD_ACCESS means you are trying to access memory at an invalid address. EXC_BAD_ACCESS表示您试图访问无效地址的内存。 It usually happens when you try to use a pointer that hasn't been initialized and is pointing to some random location in memory. 当您尝试使用尚未初始化并且指向内存中某个随机位置的指针时,通常会发生这种情况。

I don't know anything about that logging library, but I would guess is that there is some setup or initialization function that you need to call. 我对该日志库一无所知,但我想您需要调用一些设置或初始化函数。 Looking at the website it doesn't seem like there is, though. 但是,浏览该网站似乎并不存在。


One other thing that sticks out, though is probably not related, is the line 尽管可能不相关,但值得一提的是线

[self.mailButton release];

in your dealloc method. 在您的dealloc方法中。 It's probably not a problem since it is in your dealloc method, but if you're going to use a property accessor you should leave the retain and release to it. 这可能不是问题,因为它在您的dealloc方法中,但是如果您要使用属性访问器,则应保留并释放它。 If you had that line in any other place, you'd cause a EXC_BAD_ACCESS later if the mailButton property was reassigned. 如果在其他任何地方都有该行,则如果重新分配了mailButton属性,则会在以后导致EXC_BAD_ACCESS。 That's because: 那是因为:

self.mailButton = THING; // retain count +1
[self.mailButton release]; // retain count -1
self.mailButton = OTHER; // EXC_BAD_ACCESS!

That's because the third line is really a call to setMailButton: , which internally calls [THING release] , but since you already released it, you have now unbalanced your retain/release calls and so either then or later (if somebody else has retained it) release will be called on an invalid object and your program goes kablooey. 这是因为第三行实际上是对setMailButton:的调用,该调用在内部调用[THING release] ,但是由于您已经释放了它,所以您现在已经失去了对setMailButton: / release调用的平衡,因此无论是后来还是以后(如果有人保留了它) )release将在无效对象上被调用,并且您的程序进入kablooey。

Fixed the bug. 修复了该错误。 The socket was dealloced due to a missing retain. 由于缺少保留,套接字被取消分配。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM