【问题标题】:Objective c - strange leak when scrolling a table viewObjective c - 滚动表格视图时出现奇怪的泄漏
【发布时间】:2012-06-02 22:59:35
【问题描述】:

当我滚动表格视图时,我在仪器上发现了这种泄漏。
我做的滚动越多,我得到的泄漏就越多,而且它发生在我应用程序的每个表视图中。

谁能告诉我我在这里做错了什么?

       0 libsystem_c.dylib malloc
       1 libsystem_c.dylib strdup
       2 libnotify.dylib token_table_add
       3 libnotify.dylib notify_register_mach_port
       4 libnotify.dylib notify_register_dispatch
       5 CoreFoundation _CFXNotificationRegisterObserver
       6 CoreFoundation CFNotificationCenterAddObserver
       7 UIKit -[UIScrollView(Static) _startTimer:]
       8 UIKit -[UIScrollView _endPanWithEvent:]
       9 UIKit -[UIScrollView handlePan:]
      10 UIKit _UIGestureRecognizerSendActions
      11 UIKit -[UIGestureRecognizer _updateGestureWithEvent:]
      12 UIKit ___UIGestureRecognizerUpdate_block_invoke_0541
      13 UIKit _UIGestureRecognizerApplyBlocksToArray
      14 UIKit _UIGestureRecognizerUpdate
      15 UIKit _UIGestureRecognizerUpdateGesturesFromSendEvent
      16 UIKit -[UIWindow _sendGesturesForEvent:]
      17 UIKit -[UIWindow sendEvent:]
      18 UIKit -[UIApplication sendEvent:]
      19 UIKit _UIApplicationHandleEvent
      20 GraphicsServices PurpleEventCallback
      21 CoreFoundation __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__
      22 CoreFoundation __CFRunLoopDoSource1
      23 CoreFoundation __CFRunLoopRun
      24 CoreFoundation CFRunLoopRunSpecific
      25 CoreFoundation CFRunLoopRunInMode
      26 GraphicsServices GSEventRunModal
      27 UIKit UIApplicationMain
      28 MyApp 0x2bda
      29 MyApp 0x2b6f

这是表格视图 viewController .m 文件:

@implementation ContactsViewController
@synthesize data = _data;
@synthesize tableView = _tableView;

- (void)dealloc
{
    [_data release];
    [_tableView release];

    [super dealloc];
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.

    self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"bg411.png"]];
    self.title = @"Contacts";


    // init tableView
    CGRect tableFrame = self.view.bounds;

    _tableView = [[UITableView alloc] initWithFrame:tableFrame style:UITableViewStylePlain];
    _tableView.backgroundColor = [UIColor clearColor];
    _tableView.delegate = self;
    _tableView.dataSource = self;
    _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;


    [self.view addSubview:_tableView];

    // load data
    self.data = [self loadData];
}

- (NSArray *)loadData
{
    NSArray *data = [NSArray arrayWithObjects:@"1", @"2", @"3", nil];
    return data;
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.

    self.tableView = nil;
}

#pragma mark - UITableViewDataSource

- (NSInteger)numberOfRowsInOnlySection
{
    return self.data.count;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    // Return the number of sections.
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    // Return the number of rows in the section.
    return [self numberOfRowsInOnlySection];
}

- (void)configureCell:(UITableViewCell *)cell atIndexPath:(NSIndexPath *)indexPath 
{
    NSString *currData = [self.data objectAtIndex:indexPath.row];

    cell.textLabel.text = currData;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier   = @"SingleCell";

    UITableViewCell *cell = (UITableViewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];          
    }

    [self configureCell:cell atIndexPath:indexPath];

    return cell;  
}

@end

【问题讨论】:

  • 邮政编码。这对我们帮助不大。
  • 已发帖,我不知道它缝合了非常简单的代码来泄漏这么多
  • 请发布您的configureCell: 代码,以及表委托的头文件。
  • 嘿,看来我们不需要代码 :) 更新了答案,不要太担心这个泄漏。您可以根据需要创建单独的错误报告。
  • 显示您的属性已被保留或分配(.h 文件)

标签: objective-c ios uitableview memory-leaks instruments


【解决方案1】:

我敢打赌,它发生在您的某些 UIScrollViewDelegate 方法中,可能在 scrollViewDidEndDragging:willDecelerate

尝试自己运行分析以解决大部分明显的问题。


这是一个已知的 SDK 错误,请参阅 dev's forum

【讨论】:

  • 是的,它看起来像一个错误,我试过了,当我在 5.0 模拟器上运行仪器时,我没有任何泄漏,但是当我在 5.1 模拟器或我的设备上运行它时(使用5.1)我得到了泄漏。谢谢:)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-08-13
  • 1970-01-01
  • 2011-11-04
  • 1970-01-01
  • 2011-09-08
  • 2012-07-06
  • 1970-01-01
相关资源
最近更新 更多