1

我的情况:我创建了一个单例类的对象。Object 包含有关另一个对象的 Ivar 和一些 NSStrings 字段的信息。

-(id)init
 {
      [super init];     

      objectID=[NSString stringWithString:@"sqlRowId"];
      tableNameForBO=[[NSString stringWithString: @"BOComment"] lowercaseString];
      ivarListForBO=class_copyIvarList([BOComment class], &ivarCount);

      return self;
 };

当我调用该对象时,它第一次运行良好。所有字段都有正确的信息。但是当加载完成时(在 applicationDidFinishLunching 之后)应用程序调用 _UIApplicationHandleEvent 女巫删除除 objectID 之外的所有字段中的信息。

所以在程序中我有一个指向这个保持不变的单例对象的指针,但是他的字段有完全错误的信息。

NSZombie 说:

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

-[CFString _cfTypeID]: message sent to deallocated instance 0x6022a10

-[CFString _cfTypeID]: message sent to deallocated instance 0x6022bb0

并且应用程序因程序接收到的信号而崩溃:“EXC_BAD_ACCESS”。

什么会导致这种情况?没有任何想法。

非常感谢!

4

2 回答 2

0

您的对象似乎被无意中释放了。您需要确保适当地分配/保留/释放您的对象。

看看这个关于 iOS 内存管理的非常好的介绍:http: //interfacelab.com/objective-c-memory-management-for-lazy-people/

于 2011-02-22T09:46:27.223 回答
0

非常感谢!问题在于对象字段的分配不恰当。

更改 init 方法后如何:

-(id)init { self=[超级初始化];

objectID=[[NSString alloc] initWithString:@"sqlRowId"];
tableNameForBO=[[NSString alloc] initWithString: [@"BOComment" lowercaseString]];       
ivarListForBO=class_copyIvarList([BOComment class], &ivarCount);    
insertClauseForBO = [[NSString alloc] initWithString: [self getInsertClauseForBO]];

return self;

};

它工作得很好!

非常感谢它真正有帮助的答案 - 知道在哪里看。

于 2011-02-22T13:36:12.977 回答