On 15.05.2012, at 03:38, Charlie Dickman wrote:
> Note that the retainCount has changed in the first case but not in the second.
> Does anyone have any ideas as to what is happening?

 This is object-oriented programming. *anything* can have happened. While the 
external API is guaranteed and defined, encapsulation means you can't rely on 
any internal behaviours. When you call setAttributedString:, all you know is 
that you can release your copy of the string afterwards if you don't need it 
anymore. There is no guarantee what the text field will do with it. It could

- copy the string (which means the retain count stays 1, and the string gets 
deallocated when you release it)
- retain the string once
- retain the string several times
- schedule a thread that layouts the text asynchronously in the background and 
performs an additional retain on the string while it runs (which means 
depending on system load, locks and string length, it could still be retained 
by the running thread, or not, on the next line after the setAttributedString: 
call)

There is really no way for you to tell what is happening, particularly by 
looking at the retain count. There may be optimizations, there may be 
autorelease pools, there may be other helper objects that hold on to your 
string while they do work with it.

 Why are you looking at the retain count? It is a bit like looking at the 
footprints in front of a factory trying to gage how many people work there. In 
the morning they might be accurate, in the afternoon right after lunch break 
start they may be double, and if someone urgently had to go to the pharmacy you 
might be off by two. There are better ways to spend your time.

Cheers,
-- Uli Kusterer
"The Witnesses of TeachText are everywhere..."


_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to