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功能都在直方图中初始化。也许这会让我的应用变慢。 –