XCode提示 "Just Leaking" 错误的解决方法
2011-05-05 10:49
363 查看
今天随便写了一个测量代码运行时间的小程序,代码是这样的:
当我通过 run->console 查看日志输出时,出现了" *** _NSAutoreleaseNoPool(): Object 0x36acd0 of class NSCFDate autoreleased with no pool in place - just leaking" 。
对于Autorelease的对象,如果没有AutoreleasePool的话,就会提示内存泄露的错误。可问题是我怎么知道哪些对象是Autorelease的,哪些不是呢?在此发现了一个规律:如果对象不是用[[object alloc] init(withXXX)] 创建的,就是Autorelease的。
正确的写法:
NSDate* d1=[NSDate date]; //dosomthing NSDate* d2=[NSDate date]; NSLog(@"time: %f",[d2 timeIntervalSinceDate:d1]);
当我通过 run->console 查看日志输出时,出现了" *** _NSAutoreleaseNoPool(): Object 0x36acd0 of class NSCFDate autoreleased with no pool in place - just leaking" 。
对于Autorelease的对象,如果没有AutoreleasePool的话,就会提示内存泄露的错误。可问题是我怎么知道哪些对象是Autorelease的,哪些不是呢?在此发现了一个规律:如果对象不是用[[object alloc] init(withXXX)] 创建的,就是Autorelease的。
正确的写法:
NSAtuoreleasePool* pool=[NSAutoreleasePool new];
NSDate* d1=[NSDate date]; //dosomthing NSDate* d2=[NSDate date]; NSLog(@"time: %f",[d2 timeIntervalSinceDate:d1]);
[pool drain]
相关文章推荐
- 关于xcode中提示"_OBJC_CLASS_$_ClassName", referenced from"错误的解决方法
- 在IIS7.5打开网页的时候,提示: HTTP 错误 500.0 - Internal Server Error 调用 LoadLibraryEx 失败,在 ISAPI 筛选器 "C:\Windows\Microsoft.NET\Framework\v4.0.30319\\aspnet_filter.dll" 上。解决方法
- jquery提示 "object expected"的解决方法
- VB CommonDialog控件选择多个文件,报"实时错误20477",解决方法
- "路径的形式不合法"错误的解决方法
- Xcode的"Could not insert new outlet connection"问题解决方法
- vagrant up提示"Couldn't open file /path/to/base"的错误解决方法
- 关于Android4.0 emulator-arm.exe-应用程序错误,内存不能为"read"问题解决方法
- "The identity used to sign the executable is no longer valid"错误解决方法
- MySQL之——提示"mysql deamon failed to start"错误的解决方法
- 腾讯信鸽推送"CURL ERROR:name lookup timed out"错误提示解决方法
- "路径的形式不合法"错误的解决方法 [转]
- 打开PhotoShop时提示"AMT Subsystem Failure"错误的解决方法
- Android 4.0+ EditText.setError("错误提示信息")不显示文字的解决方法
- winodws quick launch 出现"Cannot create Toolbar"错误解决方法
- "对COM 组件的调用返回了错误 HRESULT E_FAIL"的解决方法
- xcode 代码不高亮 不提示语法错误 解决方法
- "Cannot forward after response has been committed "错误的正确解决方法
- "mount"错误之“RPC Error:Program not registered”解决方法
- linux下mysql提示"mysql deamon failed to start"错误的解决方法