1

I'm seeing the following error in my application:

(4446,0xa0bc94e0) malloc: * error for object 0x1d153000: pointer being freed was not allocated * set a breakpoint in malloc_error_break to debug

What does this error mean?

I am trying to display 2000 addresses in a table view, and am seeing that error in the following code with 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];

}

What could be causing this?

Brad Larson
  • 169,393
  • 45
  • 393
  • 567
milanjansari
  • 1,491
  • 2
  • 20
  • 33

2 Answers2

1

The application is giving you a hint as to how to proceed: set a breakpoint in malloc_error_break. When you get there, inspect the application's backtrace. You'll probably find that you're over-releasing an object or holding on to a stale pointer.

0

Two odd things:

obdata = [AddressBookData alloc];

You're not calling init on this object - in obj-c you usually have alloc-init together.

obdata = [arrayLocalAddressbook objectAtIndex:indexPath.row];

Then you're immediately assigning something else to this variable, so the first AddressBookData is never used.

Ben Clayton
  • 78,728
  • 25
  • 118
  • 125