0
我是Objective-C的新手,目前正在開發一個小應用程序。removeFromSuperview和內存管理
我有一些內存管理問題,想問這個問題。我有一個按鈕,我正在改變其外觀:
for (UIView *subview in button.subviews)
{
if (![subview isKindOfClass:[UIImageView class]]) // don't remove UIImageView, otherwise it will not be able to set background
{
[subview removeFromSuperview];
}
}
[button setBackgroundImage: [[imageArray objectAtIndex:itemNumber] forState:UIControlStateNormal];
/*
creating myView and myLabel here
*/
[button addSubview:myView];
[button addSubview:myLabel];
[myLabel release];
[myView release];
該代碼實際上更復雜,但沒有任何泄漏。儘管如此,每當我這樣做時,分配的對象和已用內存的數量仍在不斷增長。我怎麼解決這個問題?
非常感謝你
看起來像你的問題是與創建的標籤。剩下的其實看起來不錯... – 2010-08-17 13:46:17
有什麼問題可以在那裏?我在代碼中創建標籤,從數組中爲它分配一些文本(不要爲它創建任何對象),然後釋放標籤。我認爲[子視圖removeFromSuperview]運行時將這些數據保存在內存中,我無法做任何事情(((( – Burjua 2010-08-17 14:01:12