When I run my application, which does not use ARC, in the xcode 4.5.1 (LLDB) debugger with zombies enabled, I get this error twice (2) when calling -[super dealloc] (-[NSObject dealloc]):
* -[V2APIClient class]: message sent to deallocated instance 0x9d865c0 * -[V2APIClient class]: message sent to deallocated instance 0x9d865c0
When I run the same application in the xcode 4.4.1 (LLDB) debugger, I get the error message once (1). When I run a slightly earlier version of the same application in XCode 4.3.2, I don't get the error message at all (0). I will retry this with the same/newest code.
FYI - This appears to be exactly the same problem as this other post, which has not yet been answered: -[Foo class]: message sent to deallocated instance on [super dealloc])
I attempted to avoid reposting the same question twice, but I was advised to proceed: https://meta.stackexchange.com/questions/152226/avoiding-asking-a-question-thats-already-been-asked
Also, I also just asked the equivalent question in the Apple Developer Forums: https://devforums.apple.com/thread/171282
Finally, here is the essence of my class:
@interface ASIHTTPRequestHandler : NSObject {
id _error;
}
@property (nonatomic,retain) id error;
@end
@implementation ASIHTTPRequestHandler
@synthesize error = _error;
-(id)init
{
self = [super init];
if (self)
{
self.error = nil;
}
return self;
}
-(void)dealloc
{
self.error = nil;
[super dealloc];// this is the line that appears to cause the problems
}
@end
Please help me resolve this problem. I don't believe I am violating any memory management rules, but this error seems to imply otherwise. I'm hesitant to check in any new code until I can resolve this problem.
Thanks, Chuck
p.s. For the record, here is the calling code:
PanoTourMgrAppDelegate *ptmAppDlgt = [PanoTourMgrAppDelegate getApplicationDelegate];
Settings *settings = ptmAppDlgt.settings;
Identification *identification = ptmAppDlgt.identification;
V2APIClient *v2ApiClient = [[V2APIClient alloc] initWithSettings:settings identification:identification];
NSDictionary *result = [v2ApiClient get_application_status];
BOOL success = [v2ApiClient callWasSuccessful:result];
if (!success)
{
id error = v2ApiClient.error;
NSString *mbTitle = nil;
NSString *mbMessage=nil;
if ([error isKindOfClass:[NSString class]])
{
mbTitle = @"Application version no longer suppported";
mbMessage = (NSString*)error;
[MessageBox showWithTitle:mbTitle message:mbMessage];
}
}
[v2ApiClient release]; // This is the line that indirectly causes the messages above
If you are messaging a deallocated instance, it is because you haven't managed memory correctly. You have release that is not balanced by a retain; an over-release.
First, do a "build and analyze" on your code. Fix any problems identified.
Next, run under Instruments with zombie detection enabled and turn on the reference count tracking feature. Then, when it crashes, inspect all the retain/release events to the object in question. You'll find an extra release. The challenge is to stick a retain into the right spot to balance the release.
(And as Rob rightly points out, it may simply be a case of an extra call to release.)
This is a bug in the debugger in some versions of Xcode.
I've just had it in Xcode 4.4.1 but it is not in Xcode 4.6. To exercise the bug I created a new "Single View Application" project, switched on "Enable Zombie Objects" in the scheme dialog, and ran the following code in the View Controller, with a break point set on the final line.
- (void)viewDidLoad {
[super viewDidLoad];
NSObject *object = [[NSObject alloc] init];
[object release];
}
This results in the following message in the debugger:
-[NSObject class]: message sent to deallocated instance 0x6a7e330
You can also see the object in the variables section of the debugger now describes its class as _NSZombie_
. If you remove the breakpoint the message is no longer shown. The call to the class
method is made by the debugger after the object is correctly deallocated.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With