释放隐藏的物体?

时间:2012-01-19 18:51:01

标签: ios objective-c memory-management ios5 memory-leaks

我在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及其对象?当我分配并初始化_Histogram并隐藏_Histogram时,我的应用程序速度较慢。

1 个答案:

答案 0 :(得分:1)

问题不是很清楚。无论如何,如果您的意思是在隐藏直方图后询问如何释放您的记忆:那么您需要做的是在致电[_histogram _hidden]来电[_histogram release]; _histogram=nil;之后 同样在histogram.m文件的dealloc函数中,您应该释放在该类中初始化的所有元素。否则释放_histogram对象将不会有太大帮助