开发者

"-[CFString respondsToSelector:]: message sent to deallocated instance" when trying to access objectArray

I am trying to load next 10 rows of data in tableView when program fetches the last row in

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

I am using single function with pagenumber parameter to load the consecutive pages. It works for first fetch i.e. pagenumber 0, but when I call it again to fetch next page rows, it gives me this error

-[CFString respondsToSelector:]: message sent to deallocated instance

After banging my head for a long time, I've found that it creates this problem when trying to access the NSMutableArray of my Model objects. I am using it this way :

TableRowObjectClass* TempObject = [[TableRowObject alloc] init];
for(int i=0;i<rowArray.count;i++){
    TempObject = [rowArray objectAtIndex:i];
    NSS开发者_运维知识库tring* objectProperty = [[[NSString alloc] initWithFormat:@"String Property I need from Object to be appended with some text from TableRowObject Class : %@",TempObject.objProperty] retain];
    [propertyArray addObject:objectProperty];
    [objectProperty release];
}

Here I get array of Model Objects(TableRowObjectClass's Objects) and I want to extract objectProperty from TempObject and create and array of all those properties. Initially, for pagenumber 0, it fetches 20 rows, now when I am displaying 20th row I call fetch, which call this function to create a fresh Array of objectProperty and I call [TableView reloadData] to show the frsh feed with 20(old)+20(fresh) feeds.

Now its creating this error

-[CFString respondsToSelector:]: message sent to deallocated instance

when trying to access,

NSString* objectProperty = [[[NSString alloc] initWithFormat:@"String Property ....TableRowObject Class: %@",TempObject.objProperty] retain];

I am not sure what and where is it getting dealloc. I've spent alot of hours on this and I am not really good with objective-c memory management.

Your help is highly appreciated.


Your code pretty clearly indicates that you don't understand Objective-C or Objective-C memory management; no worries, we've all started there. Start by reading the Objective-C guide, then the Memory Management guide.

Some specific issues:

TableRowObjectClass* TempObject = [[TableRowObject alloc] init];
TempObject = [someArray objectAtIndex: 0];

That leaks. the object allocated on the first line (the variable should start with a lower case letter, too).

This:

NSString* objectProperty = [[[NSString alloc] initWithFormat:@"..."] retain];
[objectProperty release];

A double retain balanced by a single release, another leak.

That you are seeing message sent to deallocated instance errors indicates that you are over-releaseing other objects. Follow the memory management guidelines, use "build and analyze", and then use the Zombie detection tool....


There is no necessity to use

NSString* objectProperty = [[[NSString alloc] initWithFormat:@"String Property ....TableRowObject : %@",TableRowObject.objProperty] retain];

you can even use

NSString* objectProperty = [NSString stringWithFormat:@"String Property ....TableRowObject : %@",TableRowObject.objProperty];
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜