Thursday, January 2, 2014

Consult a grammar question of objective-c

Seen in head first iphone development in readwirte and retain the following explanation on the property,
readwrite: When you want the property to be modifiable by people The compiler will
.generate a getter and a setter for you. This is the default

retain: When you're dealing with object values ​​The compiler will retain the value
.you pass in and release the
old value when a new one comes in.

Will readwrite automatically generated code, the setter method is retain the new object and release old objects? I think the default readwrite property should comply with the requirements of memory management.
Reply:
Attention, learning about Object-C,
Bangding up.
Reply:
Dingding
Reply:
the setter method is retain the new release is the new target object created!
Reply:
Not too complicated to understand.
retain can be simply understood the reference count plus one, you can now use it retain, too exhausted release

setter just a simple assignment, not so complicated. Impossible to read a property will then release a memory allocation. This attribute is created when this memory has been allocated Well, on to the new retain, on the release of the old (the system to do).
Reply:
To learn. Bangding
Reply:
Official:
 
/ / Retain
- (Void) setMyObject: (id) newValue {
if (_myObject! = newValue) {
[_myObject Release];
_myObject = [newValue retain];
}
}

Reply:
Defined set method when the first release old, give it a new endowed.
Reply:
Right, @ synthesize generated accessor is consistent with memory management, you do not need to care about reference counting problems.
When you are in your destructor or other location: self.yourObject = nil; when yourObject memory will automatically be freed
Reply:
Not recommended for use readwrite, this is not conducive to memory management, although Retain need to manually release the memory, but this can reasonably manage memory is released immediately after use.
Reply:
A very important reason for you to use retain, you use the set of attribute values, then you do not know when it gave deleted.
Reply:
UP, learning the ~ ~ ~
Reply:
readwrite: When you want the property to be modifiable by people The compiler will
.generate a getter and a setter for you. This is the default
This do not control, unless you specify only read

retain: When you're dealing with object values ​​The compiler will retain the value
.you pass in and release the
old value when a new one comes in
This keyword also do not control, the role is to ensure that you are using this object is not released, the memory manager does not need your hands
Reply:
The reply was deleted at the moderator 2010-09-02 11:23:07

Reply:
reference to the 7th floor jiangyuaiqing reply:
defined set method when the first release old, give it a new endowed.

So I think the memory management should be consistent with the requirements of
Reply:
re ad wr i te
Indicates the property is readable and writable. This is the default parameters
Indicates that the property has a getter and setter one pair of accessor methods
re ado n l y
Indicate the property is read-only, and only get methods
If you try to use dot syntax for attribute assignment, will lead to compile
Error

No comments:

Post a Comment