• 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31

結末に驚いたのでメモ。

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

http://developer.apple.com/library/mac/#documentation/cocoa/conceptual/MemoryMgmt/Articles/mmObjectOwnership.html#//apple_ref/doc/uid/20000043-SW1

[意訳] Objectを作成する際にはalloc, new, copyなどで始まる関数名を使う(例、alloc, newObject, mutableCopy)

コード内の関数名を書き換えて、解決!
(newで始まるだけではダメなのですね…)

rails>>
//NG
(UILabel *)newLabelWithPrimaryColor:(UIColor *)primaryColor;

//OK
(UILabel *)createLabelWithPrimaryColor:(UIColor *)primaryColor;
<<--

posted by satoko satoko on Wed 8 Dec 2010 at 00:22 with 0 comments
Contents rssrss
NSAssertやNSLogを無効にする:-DNS_BLOCK_ASSERTIONS=1とNS_BLOCK_ASSERTIONS
GDBでview.frameを表示させる
Core Animationについてのリンク集
[iPhone] new BSDライセンスについてライセンス引用のメモ
Implementing a Container View Controller in UIViewController Class Reference
UITableView用のNSIndexPathの作り方
Xcodeのテンプレート、View-based ApplicationとWindow-based Applicationの違い
CopyOnSelectのLion対応
Xcode4のCode Snippetsを別のPCに移動する+gitで管理する
[iPhone] Singleton: iOS4以降はGCDのdispatch_onceを使う
Tags
iphone開発gitIBInterfaceBuilderiOSSIMBLSnippetsterminaltwitterxcodeXcode4
Comments rssrss
https://buy-property-uae.com/ https://buy-property-uae.com/: Many international investors believe, in today's e... 04/24 00:16
https://www.gms4you.us/ https://www.gms4you.us/: Reliable reviews confirm, in today's world using l... 04/21 19:41
https://rootskitchen.bar/ https://rootskitchen.bar/: Finished a deadly evening session punting on crash... 04/18 12:17
https://rootskitchen.bar/ https://rootskitchen.bar/: Just wrapped up a cracking arvo session grinding c... 04/17 02:19
https://si-design.ru/o-nas https://si-design.ru/o-nas: Цена дизайн-проекта стабильна и не изменится к кон... 04/10 17:15
https://corporativ-luxe.ru/magiya-solnechnoy-kapli https://corporativ-luxe.ru/magiya-solnechnoy-kapli: Мы работаем для вас без выходных и праздников htt... 04/10 16:20
https://si-design.ru/reutov https://si-design.ru/reutov: Интерьер, оформленный в стиле модернизм, отличаетс... 04/08 06:24
https://sbornye-gruzy-kitay.ru/ https://sbornye-gruzy-kitay.ru/: Реально ли привезти косметику? Там же нужны особые... 04/08 03:06