【问题标题】:Why am I being told to set a breakpoint on malloc_error_break?为什么我被告知在 malloc_error_break 上设置断点?
【发布时间】:2011-02-19 11:22:14
【问题描述】:

我在我的应用程序中看到以下错误:

(4446,0xa0bc94e0) malloc: * 对象 0x1d153000 错误:指针 被释放没有被分配 * 在 malloc_error_break 中设置断点进行调试

这个错误是什么意思?

我正在尝试在表格视图中显示 2000 个地址,并在以下代码中使用 cellForRowAtIndexPath 看到该错误:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

    static NSString *CellIdentifier = @"Cell";

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


    }

    obdata = [AddressBookData alloc];
    obdata = [arrayLocalAddressbook objectAtIndex:indexPath.row];
    // Set button Tag

    cell.textLabel.text =  [NSString  stringWithString:obdata.lastname];

    return cell;



}

// Customize the number of sections in the table view.
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    //return [indexArray count];
    return 1;

}



// Customize the number of rows in the table view.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section 
{

    return [arrayLocalAddressbook count];

}

这可能是什么原因造成的?

【问题讨论】:

标签: ios ipad


【解决方案1】:

应用程序会提示您如何继续:在malloc_error_break 中设置断点。当你到达那里时,检查应用程序的回溯。您可能会发现您正在过度释放对象或持有过时的指针。

【讨论】:

    【解决方案2】:

    两件奇怪的事:

    obdata = [AddressBookData alloc];
    

    您没有在此对象上调用 init - 在 obj-c 中,您通常将 alloc-init 放在一起。

    obdata = [arrayLocalAddressbook objectAtIndex:indexPath.row];
    

    然后你马上给这个变量赋值,所以第一个 AddressBookData 永远不会被使用。

    【讨论】:

      猜你喜欢
      • 2021-05-27
      • 2015-05-05
      • 2012-12-12
      • 1970-01-01
      • 2012-05-22
      • 2012-11-06
      • 1970-01-01
      • 2017-04-05
      • 1970-01-01
      相关资源
      最近更新 更多