Is there a way to “find mystery retains” …?

后端 未结 6 1099
离开以前
离开以前 2020-12-22 19:22

Recently I was repairing someone\'s code. There was a big class that would not dealloc. You\'d have to hit it with 5 or 6 releases to get it to dealloc.

I carefully

6条回答
  •  天命终不由人
    2020-12-22 19:39

    It is, unfortunately, not easily possible to programmatically determine what "owns" an object, since the idea of "object ownership" is a coding convention (unless you enable garbage collection).

    Stack logging is often useful (I usually use a few breakpoints with bt;continue) but that only tells you the function that called retain, not the "bigger picture" (e.g. you might "transfer ownership" with [ivar2 release]; ivar2 = ivar1; ivar1 = nil;). Sometimes it's a UIKit leak so you don't have the source code and you really have to go digging.

    If it's not a leak, however, call -release a few times and see where it crashes!

提交回复
热议问题