Objective-C “message sent to deallocated instance 0x5633b0”

后端 未结 7 1914
我寻月下人不归
我寻月下人不归 2020-12-12 14:07

I appear to have some overzealous releasing going on in my obj-C app - getting error message

\"-[myobj release]: message sent to deallocated instance

7条回答
  •  悲&欢浪女
    2020-12-12 14:39

    You're not managing your memory properly -- you're calling release/autorelease on some object more times than you're calling retain. Make sure you're following all of the rules laid out in the Memory Management Programming Guide for Cocoa.

    0x5633b0 is just the address of the memory location at which the object is stored. One thing you can try to do is to add some code to the init method:

    - (void) init
    {
        if(self == (MyClass*)0x5633b0)
            NSLog(@"Allocated object at address 0x5633b0");  // put a breakpoint on this line
        // do rest of init...
    }
    

    If you have any other init methods (e.g. initWithCoder:, which is called for objects instantiated from a XIB), make sure to put this snippet in those methods as well. Put a breakpoint on the NSLog line, and then see when it gets hit. Note that it may get hit several times, if an object is allocated at that address, deallocated, and then another object happens to be reallocated at the same address. The last hit before the crash is the one you want.

提交回复
热议问题