__NSAutoreleaseNoPool(): ... utoreleased with no pool in place - just leaking
2015-09-04 12:40
501 查看
__NSAutoreleaseNoPool(): ... utoreleased with no pool in place - just leaking
我的平台
编译时出的问题
2013-12-02 21:52:33.177 UniworkC[1662:4307] *** __NSAutoreleaseNoPool(): Object 0x134830 of class __NSCFDate autoreleased with no pool in place - just leaking
2013-12-02 21:52:33.178 UniworkC[1662:4307] *** __NSAutoreleaseNoPool(): Object 0x113900 of class NSCFNumber autoreleased with no pool in place - just leaking
2013-12-02 21:52:33.179 UniworkC[1662:4307] *** __NSAutoreleaseNoPool(): Object 0x10f590 of class NSCFLocale autoreleased with no pool in place - just leaking
2013-12-02 21:52:33.180 UniworkC[1662:4307] *** __NSAutoreleaseNoPool(): Object 0x30a4 of class NSCFString autoreleased
原来的代码
void savePNGImage(CGImageRef imageRef, NSString *path)
{
NSURL *fileURL = [NSURL fileURLWithPath:path];
CGImageDestinationRef dr = CGImageDestinationCreateWithURL(( CFURLRef)fileURL, kUTTypePNG , 1, NULL);
CGImageDestinationAddImage(dr, imageRef, NULL);
CGImageDestinationFinalize(dr);
CFRelease(dr);
}
void save()
{
CGDirectDisplayID displayID = CGMainDisplayID();
CGImageRef imageRef = CGDisplayCreateImage(displayID);
NSDate* now = [NSDate date];
NSDateFormatter* fmt = [[NSDateFormatter alloc] init];
fmt.dateFormat = @"yyMMddHHmmss";
//fmt.locale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US"];
NSString* dateString = [fmt stringFromDate:now];
NSString *path = [[NSString stringWithFormat:@"~/Desktop/tmp/%@.png", dateString ] stringByExpandingTildeInPath];
NSLog(@"save file: %@", path);
savePNGImage(imageRef, path);
CFRelease(imageRef);
}
void *screenCaputureFunc( void *para)
{
for(int i=0; i< 10; i++){
sleep(10);
save();
}
printf("end of capture\n");
return (void *)0;
}
更改为
void savePNGImage(CGImageRef imageRef, NSString *path)
{
// references: http://stackoverflow.com/questions/8225838/save-cgimageref-to-png-file-errors-arc-caused
NSURL *fileURL = [NSURL fileURLWithPath:path];
CGImageDestinationRef dr = CGImageDestinationCreateWithURL(( CFURLRef)fileURL, kUTTypePNG , 1, NULL);
CGImageDestinationAddImage(dr, imageRef, NULL);
CGImageDestinationFinalize(dr);
//CFRelease(dr);
}
void save()
{
// references: http://stackoverflow.com/questions/8225838/save-cgimageref-to-png-file-errors-arc-caused
CGDirectDisplayID displayID = CGMainDisplayID();
CGImageRef imageRef = CGDisplayCreateImage(displayID);
NSDate* now = [NSDate date];
NSDateFormatter* fmt = [[NSDateFormatter alloc] init];
fmt.dateFormat = @"yyMMddHHmmss";
//fmt.locale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US"];
NSString* dateString = [fmt stringFromDate:now];
NSString *path = [[NSString stringWithFormat:@"~/Desktop/tmp/%@.png", dateString ] stringByExpandingTildeInPath];
NSLog(@"save file: %@", path);
savePNGImage(imageRef, path);
//CFRelease(imageRef);
}
void *screenCaputureFunc( void *para)
{
for(int i=0; i< 10; i++){
sleep(10);
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
save();
[pool release];
}
printf("end of capture\n");
return (void *)0;
}
增加的自动释放的内存池。
参考
The error you get is caused by something somewhere creating an Objective-C class (NSURL) using the convenience static method [NSURL urlWithString:]. Methods that return objects that aren't "alloc" or "copy" should put the object inside an autorelease pool before returning the object. And since you haven't setup one up it'll just crash or leak memory.
I'm not sure exactly how to fix this but you need to put something like:
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
doStuff();
[pool release];
somewhere in your code.
刚刚做MAC的开发,不能给出什么更深层次的解释,只是得到这么个心得:
有不能控制内存的代码,放在自动释放的内存池中。
以后再做解释吧
参考
http://stackoverflow.com/questions/2557562/using-apple-autorelease-pools-without-objective-c
我的平台
mac os 10.6
Xcode 3.2.6
Xcode 3.2.6
编译时出的问题
2013-12-02 21:52:33.177 UniworkC[1662:4307] *** __NSAutoreleaseNoPool(): Object 0x134830 of class __NSCFDate autoreleased with no pool in place - just leaking
2013-12-02 21:52:33.178 UniworkC[1662:4307] *** __NSAutoreleaseNoPool(): Object 0x113900 of class NSCFNumber autoreleased with no pool in place - just leaking
2013-12-02 21:52:33.179 UniworkC[1662:4307] *** __NSAutoreleaseNoPool(): Object 0x10f590 of class NSCFLocale autoreleased with no pool in place - just leaking
2013-12-02 21:52:33.180 UniworkC[1662:4307] *** __NSAutoreleaseNoPool(): Object 0x30a4 of class NSCFString autoreleased
原来的代码
void savePNGImage(CGImageRef imageRef, NSString *path)
{
NSURL *fileURL = [NSURL fileURLWithPath:path];
CGImageDestinationRef dr = CGImageDestinationCreateWithURL(( CFURLRef)fileURL, kUTTypePNG , 1, NULL);
CGImageDestinationAddImage(dr, imageRef, NULL);
CGImageDestinationFinalize(dr);
CFRelease(dr);
}
void save()
{
CGDirectDisplayID displayID = CGMainDisplayID();
CGImageRef imageRef = CGDisplayCreateImage(displayID);
NSDate* now = [NSDate date];
NSDateFormatter* fmt = [[NSDateFormatter alloc] init];
fmt.dateFormat = @"yyMMddHHmmss";
//fmt.locale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US"];
NSString* dateString = [fmt stringFromDate:now];
NSString *path = [[NSString stringWithFormat:@"~/Desktop/tmp/%@.png", dateString ] stringByExpandingTildeInPath];
NSLog(@"save file: %@", path);
savePNGImage(imageRef, path);
CFRelease(imageRef);
}
void *screenCaputureFunc( void *para)
{
for(int i=0; i< 10; i++){
sleep(10);
save();
}
printf("end of capture\n");
return (void *)0;
}
更改为
void savePNGImage(CGImageRef imageRef, NSString *path)
{
// references: http://stackoverflow.com/questions/8225838/save-cgimageref-to-png-file-errors-arc-caused
NSURL *fileURL = [NSURL fileURLWithPath:path];
CGImageDestinationRef dr = CGImageDestinationCreateWithURL(( CFURLRef)fileURL, kUTTypePNG , 1, NULL);
CGImageDestinationAddImage(dr, imageRef, NULL);
CGImageDestinationFinalize(dr);
//CFRelease(dr);
}
void save()
{
// references: http://stackoverflow.com/questions/8225838/save-cgimageref-to-png-file-errors-arc-caused
CGDirectDisplayID displayID = CGMainDisplayID();
CGImageRef imageRef = CGDisplayCreateImage(displayID);
NSDate* now = [NSDate date];
NSDateFormatter* fmt = [[NSDateFormatter alloc] init];
fmt.dateFormat = @"yyMMddHHmmss";
//fmt.locale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US"];
NSString* dateString = [fmt stringFromDate:now];
NSString *path = [[NSString stringWithFormat:@"~/Desktop/tmp/%@.png", dateString ] stringByExpandingTildeInPath];
NSLog(@"save file: %@", path);
savePNGImage(imageRef, path);
//CFRelease(imageRef);
}
void *screenCaputureFunc( void *para)
{
for(int i=0; i< 10; i++){
sleep(10);
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
save();
[pool release];
}
printf("end of capture\n");
return (void *)0;
}
增加的自动释放的内存池。
参考
The error you get is caused by something somewhere creating an Objective-C class (NSURL) using the convenience static method [NSURL urlWithString:]. Methods that return objects that aren't "alloc" or "copy" should put the object inside an autorelease pool before returning the object. And since you haven't setup one up it'll just crash or leak memory.
I'm not sure exactly how to fix this but you need to put something like:
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
doStuff();
[pool release];
somewhere in your code.
刚刚做MAC的开发,不能给出什么更深层次的解释,只是得到这么个心得:
有不能控制内存的代码,放在自动释放的内存池中。
以后再做解释吧
参考
http://stackoverflow.com/questions/2557562/using-apple-autorelease-pools-without-objective-c
相关文章推荐
- Linux 双网卡绑定技术
- __NSAutoreleaseNoPool(): ... utoreleased with no pool in place - just leaking
- linux log系统图
- linux下修改hostid
- Linux命令(2):netstat命令详解
- linux log系统图
- linux下修改hostid
- vlan 以及 Linux实现的IEEE 802.1Q VLAN
- vlan 以及 Linux实现的IEEE 802.1Q VLAN
- linux 终端控制-- 多彩输出 格式排版
- linux 怎么使用一个c/c++库
- linux 终端控制-- 多彩输出 格式排版
- linux 怎么使用一个c/c++库
- 开源免费跨平台opengl opencv webgl gtk blender, opengl贴图程序
- linux内核编译环境配置
- 开源免费跨平台opengl opencv webgl gtk blender, opengl贴图程序
- linux内核编译环境配置
- RunLoop机制理解
- 并发与竞态控制
- 20150827-Linux grep文本过滤工具及正则表达式