UIPickerview在重新分配时导致堆增长

时间:2013-01-10 22:03:21

标签: ios memory-leaks uipickerview heapshot

iOS新手,尽力掌握内存管理和乐器。

我的问题是,在添加/删除选择器视图时,我会遇到奇怪的内存损失。我已经设置了一个非常基本的例子,包括两个按钮:一个创建并显示选择器。另一个将其从主视图中删除。

分析仪清洁干净,仪器不会报告任何明显的泄漏。但是 - 当我重复这个“显示和隐藏”操作时,堆内存会继续增长。

这是代码。我正在使用XCode 4.5,启用ARC:

我的ViewController.h:

#import <UIKit/UIKit.h>

@interface ViewController : UIViewController <UIPickerViewDataSource,UIPickerViewDelegate>

@property (nonatomic,strong) UIPickerView *myPickerView;

- (IBAction)pickerButtonPressed:(id)sender;
- (IBAction)freeButtonPressed:(id)sender;

@end

ViewController.m:

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (IBAction)pickerButtonPressed:(id)sender {

    NSLog(@"Tap");

    // create picker view on first button tap
    UIPickerView* newPicker = [[UIPickerView alloc] initWithFrame:CGRectMake(20, 20,160, 160)];

    newPicker.dataSource = self;
    newPicker.delegate = self;
    newPicker.showsSelectionIndicator = YES;
    self.myPickerView = newPicker;

    [self.view addSubview:newPicker];
}

- (IBAction)freeButtonPressed:(id)sender {

    NSLog(@"Free");

    // remove from view and release
    [self.myPickerView removeFromSuperview];

    self.myPickerView = nil;
}

-(NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component{

    return 5;
}

-(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView{

    return 2;
}

- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
    return @"Meh";
}

@end
仪器上的

对象列表显示UIPickerView在每次迭代时都会很好地进行,因此看起来它正在被正确释放。嗯,不太好。这是来自快照的示例:

enter image description here (对不起,我不允许发布图片)

现在,如果我实际上正确地发布了pickerview(从视图中删除并将其引用设置为nil)这些分配来自何处?

另一方面 - 堆栈跟踪上的UIPickerTableViewTitledCell事件让我感到怀疑,因为有些人在涉及泄漏的挑选视图时遇到了类似的问题(请参阅this onethis one),但我不能对我应该做的事情做出正面或反面。不确定他们是否真的与我的问题有关,但运气好的话可能指向正确的方向。

任何提示?

0 个答案:

没有答案