转自: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!");
}