无法在 iOS App 中找到废弃的内存 [英] Can't locate abandoned memory in iOS App

查看:44
本文介绍了无法在 iOS App 中找到废弃的内存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一款适用于 iOS 的游戏,但在一些游戏画面出现后,游戏被终止.我在 Xcode 中启动了仪器,我意识到我的屏幕之间的内存不断增长.ARC 已启用.

I'm developing a game for iOS and the game is being terminated after some game screens. I launched instrument in Xcode and I realized the memory keeps growing between my screens. ARC is enabled.

我使用标记生成功能来尝试跟踪前两个屏幕之间废弃的内存,如下图所示.

I used the mark generation featured to try to track the abandoned memory between the first two screens as you can see in the image below.

在启动应用程序后立即在 TitleScreen 中获取 A 代.B、C、D是从ChoosePlayer回来后的TitleScreen.

Generations A is taken in TitleScreen right after firing the app. B, C, and D are from the TitleScreen right after coming back from ChoosePlayer.

这些屏幕有一些 UIImageViews 和 UIButtons 通过 InterfaceBuilder 创建我删除了所有以编程方式创建的视图.如您所见,似乎有很多废弃的内存,但我不知道如何跟踪它们,因为堆栈来自实习 API 调用.

These screen have a few UIImageViews and UIButtons created via InterfaceBuilder I removed all programmatically created views. As you can see there seems to be a lot of abandoned memory, but I don't know how to track them since the stack comes from a intern API call.

我也没有任何其他视图控制器的参考.(没有强循环参考).

I don't have any reference to any other view controller as well. (no strong cycle reference).

以下是 TitleScreen 视图控制器的完整代码.

Below is the full code for the TitleScreen view controller.

我确定这一定是一个愚蠢的错误,但我找不到它.有任何想法吗?谢谢.

I'm sure this must be a stupid error, but I can't find it. Any Ideas? Thanks.

@interface SMTitleScreenViewController ()
@property (weak, nonatomic) IBOutlet UIButton *buttonPlay;
@property (weak, nonatomic) IBOutlet UIButton *buttonCamera;
@property (weak, nonatomic) IBOutlet UIImageView *titleBG1;
@property (weak, nonatomic) IBOutlet UIImageView *titleBG;

- (IBAction)onButtonPlay:(id)sender;
- (IBAction)onButtonCamera:(id)sender;
@end

@implementation SMTitleScreenViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self)
    {

    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];

    UIColor* color = [UIColor colorWithRed:0.2509f green:0.1176f blue:0.0745f alpha:1.0f];
    UIFont* font = [UIFont fontWithName:@"Jungle Roar" size:BUTTON_FONT_SIZE];

    NSString* playString = NSLocalizedString(@"Play", @"");
    NSString* cameraString = NSLocalizedString(@"Camera", @"");

    [self.buttonPlay setTitle:playString forState:UIControlStateNormal];
    [self.buttonPlay setTitle:playString forState:UIControlStateHighlighted];
    [self.buttonPlay setTitleColor:color forState:UIControlStateNormal];
    [self.buttonPlay setTitleColor:color forState:UIControlStateHighlighted];
    self.buttonPlay.titleLabel.font = font;

    [self.buttonCamera setTitle:cameraString forState:UIControlStateNormal];
    [self.buttonCamera setTitle:cameraString forState:UIControlStateHighlighted];
    [self.buttonCamera setTitleColor:color forState:UIControlStateNormal];
    [self.buttonCamera setTitleColor:color forState:UIControlStateHighlighted];
    self.buttonCamera.titleLabel.font = font;

}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (IBAction)onButtonPlay:(id)sender
{
    [self performSegueWithIdentifier:@"titleToChooseAnt" sender:self];
}

- (IBAction)onButtonCamera:(id)sender
{

}
@end

推荐答案

如果你担心内存没有被释放,我认为如果你回到 TitleScreen.当您在 ChoosePlayer 时查看几代人可能只会混淆情况.

If you're concerned about memory not getting released, I think the analysis will be simplified if you focus on the generations after you return to TitleScreen. Looking at generations when you're at ChoosePlayer are probably only confusing the situation.

因此,启动应用程序并获得初始标题屏幕,执行生成 A.转到 ChoosePlayer(不要执行生成),然后返回到 TitleScreen再次(稍等)并执行 B 代.对 C 代和 D 代重复该过程.

So, fire up the app and get the initial title screen, do generation A. Go to ChoosePlayer (don't do a generation) and then return to TitleScreen again (wait a second) and do generation B. Repeat that process for generation C and D.

完成后,将注意力集中在 C 代和 D 代上.不要担心 A(它在启动期间消耗了所有东西),甚至 B(可能包括可能被缓存的东西).在第二次、第三次和以后的时间里,你真的想把注意力集中在几代人身上.

Having done that, focus your attention on generations C and D. Don't worry about A (which has everything consumed during startup), nor even B (which might include stuff that might be cached). You really want to focus your attention on generations after you return the second, third, and subsequent times.

这篇关于无法在 iOS App 中找到废弃的内存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆