What is the cost of using autorelease in Cocoa?

前端 未结 11 1541
眼角桃花
眼角桃花 2020-11-30 08:19

Most of Apples documentation seems to avoid using autoreleased objects especially when creating gui views, but I want to know what the cost of using autoreleased objects is?

11条回答
  •  野趣味
    野趣味 (楼主)
    2020-11-30 08:44

    I'm surprised nobody has mentioned this yet. The biggest reason to avoid autoreleased objects when you can has nothing to do with performance. Yes, all of the performance concerns mentioned here are absolutely valid, but the biggest downside to autorelease is that it makes debugging significantly more difficult.

    If you have an overreleased object that's never autoreleased, it's trivially easy to track down. If you have a user-reported crash that happens intermittently with a backtrace somewhere south of NSPopAutoreleasePool, good luck...

提交回复
热议问题