开发者

message sent to deallocated instance 0x141dafb0 iPhone SDK

i am getting this error "message sent to deallocated instance 0x141dafb0" its comming from a UIBarButtonItem when its beeing pres开发者_如何学编程sed on the application. any help would be greatly appreciated

Error:

 *** -[PeerConnection performSelector:withObject:withObject:]: message sent to deallocated instance 0x14143ff0

PeerConnection.h

#import <UIKit/UIKit.h>
#import <GameKit/GameKit.h>

@interface PeerConnection : NSObject <GKPeerPickerControllerDelegate, GKSessionDelegate> {
 UIBarButtonItem *StartConnection;
}

- (IBAction) StartConnectionAction;

@property (nonatomic, retain) IBOutlet UIBarButtonItem *StartConnection;

@end

PeerConnection.m

    #import "PeerConnection.h"


@implementation PeerConnection
@synthesize StartConnection;


- (IBAction) StartConnectionAction {
 NSLog(@"Start Connection to the other IPhones");
 [StartConnection release];
}

- (void)dealloc {
 [super dealloc];
}

@end

i have enabled Zombie and that is all its giving to me


Don't release your StartConnection button until -dealloc. Releasing that bar button item in -StartConnectionAction is your problem--anything the UI tries to do with it after that will call a zombie.


In your case, you have released the StartConnection object. Now, when the automatic dealloc is called, the reference was not found (as already removed) and hence you got the error.


I had the same error, but was using a singleton with autorelease on shared method, took off autorelease from there and added on it's dealloc , and all works fine now.


Old Thread; But thought I might add.

If your app isn't using ARC; Use The Analyse Feature to find all the problems that may arise due to releasing/retaining objects.

Shortcut is command + shift + B

Totally useful !


This may be due to access of the instance that is already removed during GC. The error occurs in a case when you use autorelease.

ThePlannerAppDelegate *delg = [(ThePlannerAppDelegate *)[[UIApplication sharedApplication] delegate] autorelease];

Now this is most likely the GC will destroy the reference although delg points to the main window delegate.

My point is use autorelease safely.

Important: The error will occur when a message will be sent to an dead reference.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜