-[CALayer release]: message sent to deallocated instance

后端 未结 2 1204
-上瘾入骨i
-上瘾入骨i 2020-12-10 09:40

I\'m having a problem with some code in the loadView: method of one of my view controllers. Essentially I have a view which centres itself in a larger view (on an iPad) and

相关标签:
2条回答
  • 2020-12-10 10:08

    Profile your application in the simulator with 'Zombies' Instrument.

    Run your app for a while and do whatever you have to do to make your app crash. When it does, you will get a pop up like the image below and it will halt the profiling of the app:

    Zombie accessed

    Then if you click on the little arrow next to the address (0x158b3c00) .. it will take you to the object retain/release history for the object that was over released (the zombie).

    If you highlight the line above where the retain count went to -1, and open View -> Extended detail, it should point you to the stack trace and line in your code where the object was overreleased:

    Stack trace

    If you double click the class where it is occuring, it will open up your source and show you the bad line of code:

    over released code

    0 讨论(0)
  • 2020-12-10 10:08

    The over-releasing could be occurring during the objects life time and not just when they're being created. A few tips:

    • use accessors to ensure that pointers are set to nil
    • be consistent with your use of release/autorelease. Personally I prefer to have [[[Class alloc] init] autorelease] all on 1 line.
    • Learn the difference between release/autorelease. Let's Build NSAutoreleasePool is a good place to start.
    0 讨论(0)
提交回复
热议问题