結末に驚いたのでメモ。
XcodeでBuild & Analyzeすると、下記のようなメッセージが出て困っていました。UILabelのインスタンスを返すような関数なのですが、ちゃんとautoreleaseして返しているのにも関わらず、です。
Object with +0 retain counts returned to caller where a +1 (owning) retaincount is expected
メモリ管理周りをググったり、stackoverflowをうろつくなりして色々調べること数時間、原因を突き止めました:
Object with +0 retain counts returned to caller where a +1 (owning) retaincount is expected - Stack Overflow
http://stackoverflow.com/questions/3553401/object-with-0-retain-counts-returned-to-caller-where-a-1-owning-retaincount-i
結局、コード自体は間違っていなくて、「関数名が良くない」ということでした。AppleのMemory Management Programming Guideには下記のような記述があります:
You “create” an object using a method whose name begins with “alloc” or “new” or contains “copy” (for example, alloc, newObject, or mutableCopy).
[意訳] Objectを作成する際にはalloc, new, copyなどで始まる関数名を使う(例、alloc, newObject, mutableCopy)
コード内の関数名を書き換えて、解決!
(newで始まるだけではダメなのですね…)
rails>>
//NG
(UILabel *)newLabelWithPrimaryColor:(UIColor *)primaryColor;
//OK
(UILabel *)createLabelWithPrimaryColor:(UIColor *)primaryColor;
<<--