ios - 如何调试 NSZombies 和内存泄漏?

标签 ios memory nszombie

我正在开发一款连接到服务器并获取 JSON 数据的基本游戏。它在一些游戏中运行良好,但由于内存压力很快就崩溃了。我浏览了仪器并发现了一些相当令人不安的东西。 [[Class alloc]init] 实例化的几乎每个实例变量都作为 NSZombie 对象泄漏。

正如您在图片中看到的,在 5 秒内我似乎产生了 9000 次泄漏。

我正在使用 ARC。

进一步的分析表明我在使用某些方法时发生了泄漏:

-(void) playTimeUp
{

    NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle]
                                     pathForResource:@"Gameover"
                                     ofType:@"wav"]];
    AVAudioPlayer *audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:nil];
    if (audioPlayer && soundShouldPlay){
        [audioPlayer setDelegate:self];
        [audioPlayer prepareToPlay];
        [audioPlayer setVolume:.20];
        [audioPlayer play];
        [self.audioPlayers addObject:audioPlayer];
    }

} 

我也经常使用 dataWithContentsOfUrl 方法。

dispatch_async(kBackgroundQueue, ^{
        NSData* data = [NSData dataWithContentsOfURL:completeUrl];
        [self performSelectorOnMainThread:@selector(startMethod:) withObject:data   waitUntilDone:YES];

    });

谁能告诉我如何挽救这种情况,或者我做错了什么。

最佳答案

这是僵尸对象的本质。在对象被释放后打开僵尸对象来调试对象的使用显然会将任何此类对象变成泄漏。您不能同时使用僵尸进行调试和搜索内存泄漏。

关于ios - 如何调试 NSZombies 和内存泄漏?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23404278/

相关文章:

html - 在 iOS 上字体太小但在 Android 和桌面上没问题?

objective-c - 突出显示 UIAlertView 中的第一个按钮

c++ - 使用波浪号获取 int 的 MAX 值

Android Gallery 由于内存使用而崩溃

c: 调试模糊内存泄漏的策略?

iphone - 了解 Instruments 中的僵尸踪迹

ios - UIAlertView 取消按钮使应用程序崩溃

ios - 没有 ARC 的 UITableViewCell 标识符会淹没内存

iphone - 如何在 iOS 中获取信号条

ios - 什么是 NSZombie?