0

我在我的應用程序中使用ARC。 現在我面臨一個真正的問題。我需要從左向右動畫兩個視圖控制器。所以,我只是在動畫按鈕操作的兩種觀點一樣,iPhone對象不會死亡

// thanks to stackoverflow for this code 

test *control = [[test alloc] initWithNibName: @"test" bundle: nil]; 
control.view.frame = self.view.frame; 
control.view.center = CGPointMake(self.view.center.x + CGRectGetWidth(self.view.frame), self.view.center.y); 
[self.view.superview addSubview: control.view]; 

// Animate the push 

[UIView beginAnimations: nil context: NULL]; 
[UIView setAnimationDelegate: self]; 

[UIView setAnimationDidStopSelector: @selector(pushAnimationDidStop:finished:context:)]; 
control.view.center = self.view.center; 
self.view.center = CGPointMake(self.view.center.x - CGRectGetWidth(self.view.frame), self.view.center.y); 

[UIView commitAnimations]; 

- (void) pushAnimationDidStop: (NSString *) animationID finished: (NSNumber *) finished context: (void *) context 
{ 
    [self.view removeFromSuperview]; 
} 

,並在第二視圖控制器我也一樣,但改變動畫方向。

我真正的問題是當我運行這段代碼時,每次創建另一個類的對象時它都不會釋放。通過分析這些代碼,發現每次對象處於活動狀態時它都不會死亡,並且內存分配也會增加。

+0

你在哪裏分配你的*控制?它在你的按鈕動作?如果是這樣,那麼,你的問題就在那裏,因爲你每次按動按鈕時你的代碼都會分配一個新的控制器。如果你仍然想要在按鈕中分配視圖,無論出於何種原因,可以使用if(!yourViewController){分配你的控制器},以便應用程序只分配一個新的控制器,如果舊的控制器已經自動釋放弧(弧自動dealloc對象的保持無效/或沒有它的意見加載)* CMIIW – 2012-04-23 09:15:04

回答

1

您可以在啓用引用計數記錄的情況下運行分配工具。然後根據這些數據評估偏差與預期的差異。