0

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).

Bobrovsky
14.3k20 gold badges88 silver badges138 bronze badges
asked Dec 21, 2008 at 14:05

2 Answers 2

4

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.

answered Dec 21, 2008 at 14:10
Sign up to request clarification or add additional context in comments.

Comments

4

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.

answered Dec 21, 2008 at 14:49

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.