“-[CFString responsesToSelector:]:发送到已释放实例的消息"尝试访问objectArray时 [英] "-[CFString respondsToSelector:]: message sent to deallocated instance" when trying to access objectArray

查看:93
本文介绍了“-[CFString responsesToSelector:]:发送到已释放实例的消息"尝试访问objectArray时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当程序获取其中的最后一行时,我正在尝试在tableView中加载接下来的10行数据

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

我正在使用带有pagenumber参数的单个函数来加载连续的页面. 它适用于第一次获取,即页面编号0,但是当我再次调用它以获取下一页页面时,它给了我这个错误

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

长时间敲打我的头后,我发现它在尝试访问我的Model对象的NSMutableArray时会产生此问题. 我以这种方式使用它:

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];
    NSString* 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];
}

在这里,我得到了模型对象(TableRowObjectClass的对象)的数组,我想从TempObject中提取objectProperty并创建所有这些属性的数组. 最初,对于pagenumber 0,它将获取20行,现在,当我显示第20行时,我将调用fetch,该函数将调用此函数以创建一个新的objectProperty数组,然后调用[TableView reloadData]来显示带有20的frsh提要(旧)+20(新鲜)供稿.

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.

现在创建此错误

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

当尝试访问时,

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

我不确定它在什么地方和哪里得到dealloc. 我已经花了很多时间在此上,而我对Objective-C内存管理并不满意.

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.

推荐答案

您的代码清楚地表明您不了解Objective-C或Objective-C的内存管理;因此,不用担心,我们都从这里开始.首先阅读 Objective-C指南,然后内存管理指南

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.

一些特定问题:

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).

此:

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

双重保留由一次释放平衡,又有另一个泄漏.

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

您看到的message sent to deallocated instance错误表明您正在释放其他对象.遵循内存管理准则,使用构建和分析",然后使用僵尸检测工具....

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....

这篇关于“-[CFString responsesToSelector:]:发送到已释放实例的消息"尝试访问objectArray时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆