ios:泄漏警告不明确

发布于 2024-11-28 07:53:31 字数 1626 浏览 0 评论 0原文

我有以下两种方法:

-(void)playSound {
    NSString* filePath = [self getBasePath]; // <-- warnings appear when this is called
}

-(NSString*) getBasePath {
    if( debug ) NSLog(@">>> Entering %s <<<", __PRETTY_FUNCTION__);
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory , NSUserDomainMask, YES);
        NSString *documentsDir = [paths objectAtIndex:0];

    if( debug ) NSLog(@">>> Leaving %s <<<", __PRETTY_FUNCTION__);
    return documentsDir;
}

调用playsound 时,调用方法getBasePath。但随后我在控制台上收到以下警告:

2011-08-06 00:26:56.298 Alarm[82648:5d03] *** __NSAutoreleaseNoPool(): Object 0x4e350e0 of class __NSArrayM autoreleased with no pool in place - just leaking
2011-08-06 00:26:56.299 Alarm[82648:5d03] *** __NSAutoreleaseNoPool(): Object 0x4e350c0 of class NSCFString autoreleased with no pool in place - just leaking
2011-08-06 00:26:56.300 Alarm[82648:5d03] *** __NSAutoreleaseNoPool(): Object 0x4b43c00 of class NSCFString autoreleased with no pool in place - just leaking
2011-08-06 00:26:56.300 Alarm[82648:5d03] *** __NSAutoreleaseNoPool(): Object 0x4b46900 of class NSPathStore2 autoreleased with no pool in place - just leaking
2011-08-06 00:26:56.301 Alarm[82648:5d03] *** __NSAutoreleaseNoPool(): Object 0x4e37630 of class NSPathStore2 autoreleased with no pool in place - just leaking
2011-08-06 00:26:56.302 Alarm[82648:5d03] *** __NSAutoreleaseNoPool(): Object 0x4e35100 of class __NSArrayI autoreleased with no pool in place - just leaking

这是什么意思?

I've got the following two methods:

-(void)playSound {
    NSString* filePath = [self getBasePath]; // <-- warnings appear when this is called
}

and

-(NSString*) getBasePath {
    if( debug ) NSLog(@">>> Entering %s <<<", __PRETTY_FUNCTION__);
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory , NSUserDomainMask, YES);
        NSString *documentsDir = [paths objectAtIndex:0];

    if( debug ) NSLog(@">>> Leaving %s <<<", __PRETTY_FUNCTION__);
    return documentsDir;
}

When calling playsound the methode getBasePath is called. But then I get the following warning on the console:

2011-08-06 00:26:56.298 Alarm[82648:5d03] *** __NSAutoreleaseNoPool(): Object 0x4e350e0 of class __NSArrayM autoreleased with no pool in place - just leaking
2011-08-06 00:26:56.299 Alarm[82648:5d03] *** __NSAutoreleaseNoPool(): Object 0x4e350c0 of class NSCFString autoreleased with no pool in place - just leaking
2011-08-06 00:26:56.300 Alarm[82648:5d03] *** __NSAutoreleaseNoPool(): Object 0x4b43c00 of class NSCFString autoreleased with no pool in place - just leaking
2011-08-06 00:26:56.300 Alarm[82648:5d03] *** __NSAutoreleaseNoPool(): Object 0x4b46900 of class NSPathStore2 autoreleased with no pool in place - just leaking
2011-08-06 00:26:56.301 Alarm[82648:5d03] *** __NSAutoreleaseNoPool(): Object 0x4e37630 of class NSPathStore2 autoreleased with no pool in place - just leaking
2011-08-06 00:26:56.302 Alarm[82648:5d03] *** __NSAutoreleaseNoPool(): Object 0x4e35100 of class __NSArrayI autoreleased with no pool in place - just leaking

What does that mean?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

鸵鸟症 2024-12-05 07:53:31

可能您不是在主线程上执行此方法。如果这样做,您必须创建一个 NSAutoreleasePool。

-(void)playSound {
   NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
   int index = rand() % [soundFilenames count];
   NSString* filePath = [self getBasePath];
   [pool drain];
 }

Probably you are executing this method not on the main thread. If you do, you have to create a NSAutoreleasePool.

-(void)playSound {
   NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
   int index = rand() % [soundFilenames count];
   NSString* filePath = [self getBasePath];
   [pool drain];
 }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文