NSString - stringWithFormat 自动发布
@property(nonatomic, retain) NSString *password;
-(id)init {
...
password=[NSString stringWithFormat:@"%@", [[NSProcessInfo processInfo] globallyUniqueString]];
OR
password=[[NSProcessInfo processInfo] globallyUniqueString];
}
我的问题是,在执行过程中的某个随机点,密码对象会自动释放。当我使用任一作业时,效果是相同的。一旦我放入保留,问题就不再存在。我确信流程中的任何地方都没有释放密码对象 - 正如我提到的,它是在单例类中。我还检查了即使密码对象被释放,类实例也是相同的。
请任何提示!
@property(nonatomic, retain) NSString *password;
-(id)init {
...
password=[NSString stringWithFormat:@"%@", [[NSProcessInfo processInfo] globallyUniqueString]];
OR
password=[[NSProcessInfo processInfo] globallyUniqueString];
}
My problem is that during course of execution at some random point the password object gets automatically released. Effect is same when i use either of the assignments. As soon as i put in a retain, the problem no longer exists. I'm sure there is no release of password object anywhere in the flow - as i mentioned it is in a singleton class. I also checked that the class instance is same even when the password object is released.
Any hints please!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您分配 iVar,而不是属性...
因此,由于您不使用 setter 方法,因此不会保留您的对象。
使用该属性来代替:
You assign the iVar, not the property...
So as you don't use the setter method, your object is not retained.
Use the property instead:
您可以使用...
还可以在 内存管理。我还会在您的代码中设置断点,然后查看您的对象是否被释放。
You could use...
Also checkout Apple's doc on memory management. I would also set breakpoints in your code and see then your object gets released.