转自:http://year-2002.blog.163.com/blog/static/2493812320118795838457/
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init]; NSData* data = [NSData dataWithBytes:"asklaskdxjgr" length:12]; [data release]; [pool release];
autorelease pool 自动释放 ,我们又手工释放,所以crash掉了;
Here"s what we do:
Click on the "Targets" tab, open "Executables" and select the app (In XCode 2.0, double-click the executable in the file tree and select the arguments tab to enter environment variables). In the executable settings, add the following environment variables and set their values to "YES" (without the quotes):
NSDebugEnabled NSZombieEnabled MallocStackLogging
You may also want the following environment variable set to YES:
if you run under gdb, you may enter:MallocStackLoggingNoCompact/////////////////////////////
(gdb) shell malloc_history 3939 0xa4e10
以下例子可以查看变量有没有设置成功:
if( getenv("NSZombieEnabled") || getenv("NSAutoreleaseFreedObjectCheckEnabled") ) {
NSLog(@"NSZombieEnabled/NSAutoreleaseFreedObjectCheckEnabled enabled!");
}
本文探讨了Objective-C中自动释放池的使用方法,并通过一个简单的示例代码展示了不当使用自动释放池导致程序崩溃的问题。此外,还介绍了如何通过设置环境变量来启用调试功能,以便更好地追踪和解决内存管理方面的问题。
766

被折叠的 条评论
为什么被折叠?



