Hi guys,
i have some questions about objective-c's memory management,
let's say:
NSString * test= [[NSString alloc] init ]
test=@"msg";
[object setStr1: test ]; // declared as: @property(copy, readwrite)
[object setStr2: test ]; // declared as: @property(retain, readwrite)
[object setStr3: test ]; // declared as: @property(assign, readwrite)
test=@"some other string"
I think str1
will have a copy of test
s content: str1
will point to one adress of the memory (heap) that contais msg
, this address is not the same pointed by test
. right?
about str2:
1. what does it store?, i guess the same address that points test
, but it will increase the reference counter of test
to 2.
2. when i change the test's content, what does str2 have? I guess it still points to msg
about str3: it's incorrect, right?, what does assign
do?
thanks.
bonus question:
NSString * test= [[NSString alloc] init ]
test=@"msg";
test=@"something";
should i release test before changing its content?