ios – 在我的应用程序中找到了一个N​​SZombie …现在怎样?

ios – 在我的应用程序中找到了一个N​​SZombie …现在怎样?,第1张

概述我有一个NSManagedObject的子类,有一些“整数32”属性,真的是枚举.这些枚举在我的模型的.h文件中定义,如下所示: typedef enum { AMOwningCompanyACME, AMOwningCompanyABC, AMOwningCompanyOther} AMOwningCompany; 我需要显示一个表视图,显示此自定义对象的每个属性的值, 我有一个NSManagedobject的子类,有一些“整数32”属性,真的是枚举.这些枚举在我的模型的.h文件中定义,如下所示:

typedef enum {    AMOwningCompanyAcme,AMOwningCompanyABC,AMOwningCompanyOther} AMOwningCompany;

我需要显示一个表视图,显示此自定义对象的每个属性的值,因此对于每个枚举,我有一个看起来像这样的方法来返回字符串值:

-(NSArray*)stringsForAMOwningCompany{    return [NSArray arrayWithObjects:@"Acme Co.",@"ABC Co.",@"Other",nil];}

在我的表视图中,我遍历NSManagedobject的属性(使用NSEntityDescription的attributesByname,对于每个属性,我调用一个调用相应“stringsFor”方法的辅助方法来返回该特定属性的字符串:

-(NSArray*)getStringsArrayForAttribute:(Nsstring*)attributename{    SEL methodSelector = NSSelectorFromString([self methodnameForAttributenamed:attributename]);    NSInvocation* invocation = [NSInvocation invocationWithMethodSignature:[[AMProperty class] instanceMethodSignatureForSelector:methodSelector]];    [invocation setSelector:methodSelector];    [invocation setTarget:self.editingPole];    [invocation invoke];    NSArray* returnValue = nil;    [invocation getReturnValue:&returnValue];    return returnValue;}

我的表视图的cellForRowAtIndexPath如下所示:

...Nsstring* itemname = self.tableData[indexPath.row];NSAttributeDescription* desc = itemAttributes[itemname];Nsstring* cellIDentifIEr = [self cellIDentifIErForAttribute:desc]; // checks the attribute type and returns a different custom cell IDentifIEr accordinglyif ([cellIDentifIEr isEqualToString:@"enumCell"]){    // dequeue cell,customize it    UItableVIEwCell* enumCell = ...    ...    NSArray* stringValues = [[NSArray alloc] initWithArray:[self getStringArrayForAttribute:itemname]];    int currentValue = [(NSNumber*)[self.editingPole valueForKey:itemname] intValue];    enumCell.detailTextLabel.text = (Nsstring*)stringValues[currentValue];    return enumCell;}...

对于其中一个属性,我一直在NSInvocation的返回数组上崩溃:

-[__NSArrayI release]: message sent to deallocated instance 0x856a4b0

使用ZombIEs Profiler,我看到:

我正在使用ARC.我该如何进一步调试?

解决方法 我最近遇到了一个非常类似的问题,我花了一段时间才弄明白我做错了什么.这里发布了一个额外的版本 – 因为你的指针returnValue是__strong(默认值),ARC认为该对象是通过该指针拥有的,但事实并非如此.

– [NSInvocation getReturnValue:]不取得它的所有权,并且通过指针地址的“赋值”绕过ARC通常使用的objc_storeStrong().

解决方案很简单:将指针标记为__unsafe_unretained.这是事实;该对象不会通过此指针保留(如果它是__strong那样),并且ARC不能在此处释放它.

总结

以上是内存溢出为你收集整理的ios – 在我的应用程序中找到了一个N​​SZombie …现在怎样?全部内容,希望文章能够帮你解决ios – 在我的应用程序中找到了一个N​​SZombie …现在怎样?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1076501.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-26
下一篇2022-05-26

发表评论

登录后才能评论

评论列表(0条)

    保存