0
我在iOS上編寫應用程序。我有主類和UIView
子類與一些UILabel
字段。發佈隱藏的對象?
我想在子類的對象不在屏幕上時釋放內存(我隱藏了動畫的視圖)。我怎樣才能做到這一點?
ViewController.h
#import "Histogram.h"
#import "HistogramDelegate.h"
{
UIScrollView *filtersScrollView;
UITapGestureRecognizer *tapGesture;
UISwipeGestureRecognizer *swipeGesture;
...some UILabels and other components.
Histogram *_Histogram;
}
@property (nonatomic, retain) Histogram *_Histogram;
... other properties
... some functions
@end
ViewController.m
-(void)viewDidLoad {
_Histogram = [[Histogram alloc] initWithFrame:...];
}
-(void)viewDidUnload // here i add nil value to objects, for ex. UIScrollView = nil.
-(void)someFunc {
[_Histogram hideHistogram];
}
Histogram.h
//some objects/fields like UILabels, UISliders, UIViews
Histogram.m
some functions.
-(void)hideHistogram {
}
如何和我在哪裏可以釋放_Histogram
和他的對象從內存時超出屏幕的?當我分配和init _Histogram
,當我隱藏_Histogram
,我的應用程序更慢。
是的,但是當我鍵入[_Histogram release]我有錯誤:'release'is unavailable:not available in automatic reference counting mode:/ –
這是因爲你正在使用自動引用計數,該引用計數在最新的Xcode中默認啓用。所以如果你不需要_histogram,只需將它設爲零。這樣你就不會指它,它會自動釋放。 – aqs
當我做_histogram =零;應用程序仍然很慢。我在直方圖中使用S7GraphView庫。我應該在他的方法中創建3個數組嗎?所有S7GraphView功能都在直方圖中初始化。也許這會讓我的應用變慢。 –