[英]Can't locate abandoned memory in iOS App
我正在為iOS開發游戲,並且在某些游戲屏幕出現后游戲將終止。 我在Xcode中啟動了樂器,然后意識到內存在屏幕之間不斷增長。 ARC已啟用。
我使用了標記生成功能來嘗試跟蹤前兩個屏幕之間的廢棄內存,如下圖所示。
觸發應用后,A世代即在TitleScreen中獲取。 B,C和D是從ChoosePlayer返回后立即從TitleScreen中獲得的。
這些屏幕上有一些通過InterfaceBuilder創建的UIImageViews和UIButtons我刪除了所有以編程方式創建的視圖。 如您所見,似乎有很多廢棄的內存,但是我不知道如何跟蹤它們,因為堆棧來自內部API調用。
我也沒有任何其他視圖控制器的引用。 (無強循環參考)。
下面是TitleScreen視圖控制器的完整代碼。
我確定這肯定是一個愚蠢的錯誤,但我找不到它。 有任何想法嗎? 謝謝。
@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
中查看世代可能只會使情況ChoosePlayer
混亂。
因此,啟動應用程序並獲取初始標題屏幕,執行A代。轉到ChoosePlayer
(不執行一代),然后再次返回TitleScreen
(等待一秒鍾),執行B代。為C代重復該過程和D。
完成此操作后,將注意力集中在C和D代上。不必擔心A(啟動時消耗了所有東西),甚至B也不必擔心(它可能包含可能緩存的內容)。 您確實希望在第二次,第三次及以后的返回之后將注意力集中在世代上。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.