目标 C:释放 int/float 属性
我在理解某些事情时遇到了一些困难。我的应用程序中有很多属性:
@property (nonatomic, retain) AVAudioPlayer *audioPlayer;
@property (readwrite) NSInteger buttonCount;
@property (nonatomic, retain) NSString *soundSelected;
@property (readwrite) float fadeDecrease;
@property (readwrite) float fadeDelay;
这些显然都是在我的 .m 文件中综合的。 然而,虽然audioPlayer和soundSelected在dealloc中释放得很好,但int buttonCount给出了这个警告: “接收器类型‘NSInteger’无效” 浮点数实际上让编译器哭泣: “无法转换为指针类型”
这与它们不是对象类型和/或未保留这一事实有关吗? 他们不被释放可以吗?
谢谢。
I'm having some trouble understanding something. I got a bunch of propeties in my app:
@property (nonatomic, retain) AVAudioPlayer *audioPlayer;
@property (readwrite) NSInteger buttonCount;
@property (nonatomic, retain) NSString *soundSelected;
@property (readwrite) float fadeDecrease;
@property (readwrite) float fadeDelay;
These are obviously all synthesized in my .m file.
However, while audioPlayer and soundSelected are released fine in dealloc, the int buttonCount gives this warning:
"Invalid receiver type 'NSInteger'"
and the floats actually make the compiler cry with:
"Cannot convert to a pointer type"
Has this got something to do with the fact that they are not of object types and/or not retained?
Is it OK that they are not released?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
NSInteger
与float
一样,不是 Objective-C 类型,也不遵循通常的保留/释放模型。他们只是原始人。为属性赋值就足够了。应该就是你所需要的。
然而,
NSNumber
确实遵循通常的保留/释放周期,因此请相应地添加属性。NSInteger
, likefloat
, are not Objective-C types and do not follow the usual retain/release model. They're just primitives. Assigning values to the property will be sufficient.should be all you need.
NSNumber
however does follow the usual retain/release cycle, so add attributes accordingly.是的。您只能释放具有保留计数的对象。像 int、float 和 NSInteger 这样的原始数据类型不需要保留/释放,因为它们不是引用内存其他部分的指针。
如果您想了解有关内存管理的更多信息,请尝试查看此文档页面:
http://developer.apple.com/library/ios/#documentation/Cocoa/Conceptual/MemoryMgmt/MemoryMgmt.html%23// apple_ref/doc/uid/10000011-SW1
Yes. You can only release objects that have a retain count. Primitive datatypes like int, float, and NSInteger do not need to be retained/released because they are not pointers referring to other parts of memory.
If you want to learn more about memory management, try taking a look at this documentation page:
http://developer.apple.com/library/ios/#documentation/Cocoa/Conceptual/MemoryMgmt/MemoryMgmt.html%23//apple_ref/doc/uid/10000011-SW1