Executing this code:
mainLyr = [[CALayer layer] retain];
[mainLyr setFrame:CGRectMake(0.0,0.0,23.0,23.0)];
in debugger, I found that after retain
, the reference count of mainLyr
is 2. This is correct.
But after setFrame
, the reference count increased to 3. Why? And how to find out if a method will increase or decrease the reference count (can not find that in reference manual).
2 Answers 2
As has been said many times on stackoverflow, don't rely on the refcount for your memory management. Follow the memory management rules and you'll do just fine.
Comments
Graham is correct, but the reason it increments the reference count is that you're using Core Animation here; a layer's frame change is animated, and during the animation the target object is retained. After the animation duration (by default 0.25 sec, I believe) your reference count should drop back by 1.