views:

403

answers:

2

having these code:

mainLyr = [[CALayer layer] retain]; [mainLyr setFrame:CGRectMake(0.0,0.0,23.0,23.0)];

in debugger, I found that after retatin, the refcount of mainLyr is 2, this is correct. but after setFrame, the refcount increased to 3, why? and how to determine if a method will increase or decrease the refcount (can not find that in reference manual).

Thanks.

+4  A: 

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.

Graham Lee
+3  A: 

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.

Ben Gottlieb