EXC_BAD_ACCESS错误 [英] EXC_BAD_ACCESS error

查看:197
本文介绍了EXC_BAD_ACCESS错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我做了一个应该运行不变的应用程序,直到我停止它。它基本上做的是从连接的另一个设备获取一些数据,并使用 NSURLConnection 定期发送数据到服务器,并定期从服务器读取数据,并将数据可视化为图形使用 NSXMLParser

I made an application that should run constant until I stop it. What it basically does is getting some data from connected another device and send that data to the server periodically using NSURLConnection, and read data from the server periodically and visualize that data as a graph using NSXMLParser.

我运行仪器来检查分配和泄漏。没有泄漏。内存监视器显示一致的5.2 MB。 Objectalloc图是稳定的,objectallo的净字节是arouend 480000,#net是6400左右。

I ran the instrument to check allocs and leaks. No leak at all. memory monitor shows consistent 5.2 MB. Objectalloc graph is stable, Net bytes of objectallo is arouend 480000 and #net is around 6400.

它约10〜15小时后崩溃。所以我在 malloc_error_break 中添加了断点。
现在我在Debugger控制台上大约12小时后收到 EXC_BAD_ACCESS 错误。

It crashed about 10 ~ 15 hours later. So I added breakpoint in malloc_error_break. Now I gets "EXC_BAD_ACCESS" error on Debugger console about 12 hours later.

任何想法?

一个可疑部分是 SENDING 数据。

One suspicious part is SENDING data.


- (void) sendDataToServerWithX:(float)x Y:(float)y{ 
NSAutoreleasePool *uiUpdatePool = [[NSAutoreleasePool alloc] init]; 
NSString *urlString = [[NSString alloc] initWithFormat:@"http://www.url.com/save_data.php?user=user1&x=%f&y=%f", x, y];
NSURLRequest *theRequest=[NSURLRequest requestWithURL:[NSURL URLWithString:urlString] cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0];
NSURLConnection *theConnection=[[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
if (theConnection) { NSLog(@"sending success"); } //else { }

NSLog(@data sent。);

[urlString release];

[theConnection release];
[uiUpdatePool drain];
}

NSLog( @"data sent.");
[urlString release];
[theConnection release]; [uiUpdatePool drain]; }

另一个可疑部分是 READING data:

Another suspicious part is READING data:


- (void) readCurrentDataFromServer: (NSTimer *) timer {
NSAutoreleasePool *uiUpdatePool = [[NSAutoreleasePool alloc] init]; XMLParser *parser = [[XMLParser alloc] initXMLParser];
NSURL *url = [[NSURL alloc] initWithString:aString]; NSXMLParser *readXmlParser = [[NSXMLParser alloc] initWithContentsOfURL:url];
[readXmlParser setDelegate:parser]; [readXmlParser parse];

(...)

[解析器版本];

[url release ];

[readXmlParser release];
[uiUpdatePool drain];
}

[parser release];
[url release];
[readXmlParser release]; [uiUpdatePool drain]; }

推荐答案

它在iPhone模拟器与Guard Malloc(在Xcode的运行菜单)启用。这是一个特殊的设置,旨在使隐藏的内存访问错误导致立即崩溃,而不是隐藏一段时间。 (它也会使你的应用程序非常慢,消耗比正常更多的内存,这就是为什么它不总是打开。)它不能确定它会有帮助,但它可能。

Try running it in the iPhone Simulator with "Guard Malloc" (in Xcode's Run menu) enabled. That's a special setting designed to make hidden memory-access bugs cause immediate crashes rather than hiding for a while. (It will also make your app very slow and consume much more memory than normal, which is why it isn't always on.) It's not certain that it will help, but it might.

UPDATE :上面的说明是针对Xcode 3的。在Xcode 4中,通过在工具栏中单击你的方案名称,选择编辑方案,点击工作表源列表,选择诊断选项卡,然后选中启用Guard Malloc。

UPDATE: The instructions above are for Xcode 3. In Xcode 4, turn on Guard Malloc by clicking your scheme name in the toolbar, selecting "Edit Scheme", clicking "Run" in the sheet's source list, choosing the "Diagnostics" tab, and checking "Enable Guard Malloc".

这篇关于EXC_BAD_ACCESS错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆