Goal C: Release int / float properties

I am having trouble understanding something. I got a bunch of props in my application:

@property (nonatomic, retain) AVAudioPlayer *audioPlayer; @property (readwrite) NSInteger buttonCount; @property (nonatomic, retain) NSString *soundSelected; @property (readwrite) float fadeDecrease; @property (readwrite) float fadeDelay; 

They are obviously all synthesized in my .m file. However, while audioPlayer and soundSelected are fined in dealloc, the int buttonCount gives this warning: "An invalid receiver type" NSInteger "and floats do make the compiler shout:" Cannot convert to pointer type "

Is it due to the fact that they do not belong to the types of objects and / or are not saved? Is it normal that they are not released?

Thanks.

+4
source share
2 answers

NSInteger , such as float , are not Objective-C and do not follow the usual save / release model. They are just primitives. Assigning values ​​to this property will suffice.

 @property (readwrite, assign) NSInteger buttonCount; 

should be all you need.

NSNumber , however, follows the usual save / release cycle, so add attributes accordingly.

+14
source

This is due to the fact that the fact that they do not belong to the types of objects and / or are not saved? Is it normal that they are not released?

Yes. You can only issue objects that have a save account. Primitive data types, such as int, float, and NSInteger, do not need to be stored / freed, as they are not pointers to other parts of memory.

If you want to know more about memory management, try looking at this documentation page:

http://developer.apple.com/library/ios/#documentation/Cocoa/Conceptual/MemoryMgmt/MemoryMgmt.html%23//apple_ref/doc/uid/10000011-SW1

+4
source

Source: https://habr.com/ru/post/1343082/


All Articles