iPad App仅在手动启动时(从跳板启动)崩溃。怀疑内存问题

时间:2012-01-20 21:05:31

标签: iphone xcode ipad memory-management springboard

我一直试图解决这个问题2天了,这让我发疯了。当Xcode启动应用程序时,它工作正常,但如果我从Springboard手动启动应用程序,则崩溃。控制台打印出来:

Jan 20 15:26:29 unknown UIKitApplication:com.yourcompany.ThinClient[0x28cf][1119] <Notice>: ThinClient(1119,0x3db0000) malloc: *** error for object 0x643434: incorrect checksum for freed object - object was probably modified after being freed.
Jan 20 15:26:29 unknown UIKitApplication:com.yourcompany.ThinClient[0x28cf][1119] <Notice>: *** set a breakpoint in malloc_error_break to debug
Jan 20 15:26:29 unknown ThinClient[1119] <Error>: ThinClient(1119,0x3db0000) malloc: *** error for object 0x643434: incorrect checksum for freed object - object was probably modified after being freed.
    *** set a breakpoint in malloc_error_break to debug

崩溃线程(通常)的堆栈看起来像这样,虽然有时它会在不同的位置崩溃:

Thread 5 Crashed:
0   libsystem_kernel.dylib          0x33d4da1c __pthread_kill + 8
1   libsystem_c.dylib               0x353523b4 pthread_kill + 52
2   libsystem_c.dylib               0x3534abf8 abort + 72
3   libsystem_c.dylib               0x3535e822 szone_error + 210
4   libsystem_c.dylib               0x3535e920 free_list_checksum_botch + 16
5   libsystem_c.dylib               0x35361722 tiny_malloc_from_free_list + 82
6   libsystem_c.dylib               0x35361e76 szone_malloc_should_clear + 166
7   libsystem_c.dylib               0x35362fd4 szone_malloc + 4
8   libsystem_c.dylib               0x35386230 malloc_zone_malloc + 48
9   libsystem_c.dylib               0x35386c2c malloc + 28
10  ThinClient                      0x0000590c -[MySocket readBytes:] (MySocket.m:231)
11  ThinClient                      0x00007b7e -[ThinServerTalker onSocket:readCallbackBytesWaiting:] (ThinServerTalker.m:362)
12  ThinClient                      0x000057e2 ReadDataCB (MySocket.m:201)
13  CoreFoundation                  0x33cca48a __CFSocketDoCallback + 334
14  CoreFoundation                  0x33ccb4a2 __CFSocketPerformV0 + 78
15  CoreFoundation                  0x33cc5a72 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 6
16  CoreFoundation                  0x33cc7758 __CFRunLoopDoSources0 + 376
17  CoreFoundation                  0x33cc84e4 __CFRunLoopRun + 224
18  CoreFoundation                  0x33c58ebc CFRunLoopRunSpecific + 224
19  CoreFoundation                  0x33c9b6d2 CFRunLoopRun + 42
20  ThinClient                      0x00005656 -[MySocket _connect] (MySocket.m:160)
21  Foundation                      0x33d71382 -[NSThread main] + 38
22  Foundation                      0x33de35c6 __NSThread__main__ + 966
23  libsystem_c.dylib               0x3535230a _pthread_start + 242
24  libsystem_c.dylib               0x35353bb4 thread_start + 0

我怀疑它是从应用程序写入已经释放的内存,所以我已经尝试了一些东西:

  • 我尝试使用guard malloc,scribble,guard edges,zombie对象,malloc堆栈等调试应用程序。
  • 我尝试使用应用程序崩溃并在那里发现问题的代码(我不相信那里存在问题,因为应用程序在不同的地方崩溃,但它们彼此靠近)
  • 我尝试了并注释掉了所有的free()函数调用。

我还没有发现问题!如果有人能够对此有所了解,我将不胜感激!谢谢!有什么建议吗?

编辑:如果从跳板启动应用程序,应用程序每次都会崩溃,但如果Xcode启动它,它将正常运行

1 个答案:

答案 0 :(得分:1)

我发现了这个问题。我从函数返回一个NSData对象中字节的直接指针。我只是用一个名为“ - (NSData *)getDataCopy”的函数替换了一个名为“ - (char *)getBytes”的函数。获取数据副本而不是返回数据类的自动释放副本。

重申:

我有这个:

-(char*)getBytes{
    return _data.bytes;}

我将其替换为

-(NSData*)getDataCopy{
return [NSData dataWithData:_data];
}

问题是我写的是已经发布的内存。