Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/101.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 我的后台应用程序使用70Mb,如何释放内存?_Ios_Objective C_Sprite Kit - Fatal编程技术网

Ios 我的后台应用程序使用70Mb,如何释放内存?

Ios 我的后台应用程序使用70Mb,如何释放内存?,ios,objective-c,sprite-kit,Ios,Objective C,Sprite Kit,我有一个游戏,当我以60帧/秒的速度运行时,在各个方面都或多或少有不足之处,但问题是当我进入后台时。我用两种方法暂停,第一种方法在您触摸游戏内暂停按钮时运行: -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { for (UITouch *touch in touches) { CGPoint location3 = [touch locationInN

我有一个游戏,当我以60帧/秒的速度运行时,在各个方面都或多或少有不足之处,但问题是当我进入后台时。我用两种方法暂停,第一种方法在您触摸游戏内暂停按钮时运行:

    -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
        for (UITouch *touch in touches)
        {
            CGPoint location3 = [touch locationInNode:self.pauseLayer];
            SKSpriteNode *touchedNode3 = (SKSpriteNode *)[self.pauseLayer nodeAtPoint:location3];

            if (touchedNode3.physicsBody.categoryBitMask == pausa)
            {
                    if (_gameIsPaused == NO) 
{
                    [self.world setPaused:YES];
                    [self.backWorld setPaused:YES];
                    [self setPaused:YES];
                    _gameIsPaused = YES;
                    [self.pauseLayer setPaused:NO];
                    [self showPauseMenu];
                }
else
                {
                    [self.world setPaused:NO];
                    [self.backWorld setPaused:NO];
                    [self setPaused:NO];
                    _gameIsPaused = NO;
                    [self hidePauseMenu];
                    [self.pauseLayer setPaused:YES];

                }
当您输入后台时,我的应用程序中有以下内容:

- (void)applicationWillResignActive:(UIApplication *)application
{
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.

[[AVAudioSession sharedInstance] setActive:NO error:nil];
SKView* view = [self getSKViewSubview];

    if (view) {
        view.paused = YES;
    }
}

问题是在后台运行时,我的应用程序仍在消耗内存,有时当我打开另一个应用程序时,我的游戏会崩溃。在此图像中,您可以看到运行后台时我的应用程序的使用情况:

我的问题是,如果有办法防止崩溃,我应该在离开游戏之前手动释放内存来完成任务吗??
我尝试了两种方式输入背景,一种是启用暂停菜单,另一种是禁用暂停菜单。有时它会崩溃,看起来是随机的。因此,内存消耗总是相同的。最好的做法是释放所有东西,除了重要的东西,比如点数、玩家的位置、时间、你现在的世界等等,然后摧毁其他一切?在这种情况下,我怎么能这样做?要销毁所有内容并保留分数、分数等?

iOS会在后台应用程序需要更多内存时杀死它,而不会对应用程序发出任何警告。由应用程序在进入后台时保存其状态,以防系统将其杀死,然后在启动时再次恢复状态

如果系统决定终止你的应用程序时你还在Xcode中调试,如果我没记错的话,它会显示为SIGKILL,但这不是崩溃,iOS只是在没有警告的情况下终止你的应用程序


降低后台内存使用率的唯一方法是在应用程序进入后台时卸载图像等,但对于一款在用户切换应用程序时可能导致恼人的加载/冻结的游戏。。。通常,当收到内存不足警告时,所有应用程序需要释放任何不必要的或可重新加载的资源(缓存图像等)…

这是我最接近SIGKILL的事情,它发生在我打开另一个游戏时,一个类似行尸走肉的3D游戏。只发生在大型应用程序中,而不是whats'app或safari,并且不会恢复任何状态


我在尝试复制崩溃来上传图像时得到了这个结果。

你最好的办法是复制和分析当你的应用程序在后台分别从中恢复时发生的崩溃。不过,你不必担心你的应用程序的后台内存使用情况,iOS会解决这个问题。我相信它甚至可以拍摄一个内存快照并将其存储在磁盘上,以便以后继续,而不是将内容保存在“真实”内存中。此外,如果您发现后台模式有问题,您可以简单地关闭应用程序的后台模式。