dealloc method is calling three time, during the runtime
I'm developing an iphone application and i have small problem on it. I'm using popup caller methods into my appdelegate.m file bellow like that
-(void)OpenInfo{
InfoDetail *detail = [[InfoDetail alloc] initWithNibName:@"InfoDetail" bundle:nil];
self.infoDetail = detail;
[detail release];
[window addSubview:detail.view];
}
-(void)OpenNetworkSelection{
NetworkSelection *netsel = [[NetworkSelection alloc] initWithNibName:@"NetworkSelection" bundle:nil] ;
self.networkselection = netsel;
[netsel release];
[window addSubview:netsel.view];
}
And I'm calling these methods from inside of views like that
StatusFoxAppDelegate *delegate = (StatusFoxAppDelegate*)[[UIApplication sharedApplication] delegate];
[delegate OpenInfo]; 开发者_运维知识库
And these helper views and opener views communicating via NSNotificationCenter.
My problem is as you can see "OpenInfo" and "OpenNetworkSelection" methods contains view instance creation logics.
When i called OpenInfo method it's working perfect as should be. But "OpenNetworkSelection" isn't working it's throwing when i tried second time *** -[UIButton release]: message sent to deallocated instance 0x3dbdb50 error.
Ok I understood that. Then i put NSlog line into the Dealloc overload of NetworkSelection.m
and OpenInfo.m files, because i need to differences of behaviours.So, OpenInfo dealloc methods is working on when the view closed (I mean removed from superview). But NetworkSelection's dealloc method executing three times. I didn't find to problem source.
Can someone tell me, what i'm doing wrong ?
Thank you
Edit :
Guys, i found something wrong into my NetworkSelection view controller. More description is; i saw these lines of code into my viewcontroller.
CommonGateway *gw = [[CommonGateway alloc] InitWithDefaults];
self.gateway = gw;
[self.gateway GetAvailableNetworkList];
[self.gateway setCommDelegate:self];
[gw release];
In these lines of code i'm making async server calls, when i commented out these lines, my viewcontroller worked perfectly, then i created "LoadDataFromServer" method and i passed CommonGateway instance from source that appdelage like that
- (void)LoadDataFromServer{
CommonGateway *gw = [[CommonGateway alloc] InitWithDefaults];
self.gateway = gw;
[self.gateway GetAvailableNetworkList];
[self.gateway setCommDelegate:self];
[gw release];
}
My appdelegate code change to;
-(void)OpenNetworkSelection{
NetworkSelection *netsel = [[NetworkSelection alloc] initWithNibName:@"NetworkSelection" bundle:nil] ;
self.networkselection = netsel;
self.networkselection.gateway = commonGateway;
[netsel release];
[window addSubview:self.networkselection.view];
[self.networkselection LoadDataFromServer];
}
But result same, if i comment out "[self.networkselection LoadDataFromServer];" line then it's working. And my CommonGateway class notify to caller via NSNotificationCenter.
I think it will be gives more clue for solving problem.
Thank you again
You release detail
here:
[detail release];
And then you try to use it immediately afterwards:
[window addSubview:detail.view];
Your application crashes because you released detail
but you still tried to access its (now non-existent) properties.
So you may want to use, instead, your ivars, e.g.:
[window addSubview:self.infoDetail.view];
Or:
[window addSubview:[self.infoDetail view]];
You may want to read through Apple's Memory Management Programming Guide.
If your getting a call to dealloc three times then that suggest that you have three instances of the same class instead of one. You should set a breakpoint in the dealloc and check the address of the instance to see if it is the same each time. I suspect it won't be.
However, if you did not make a call to [super dealloc]
when you overrode dealloc
it's possible the object isn't actually being deallocated but is just releasing its iVars. In that case, the system might call the same instance's dealloc repeatedly while trying to kill it.
Guys i found my problem source. Problem exactly inside of the CommonGateway class implementation In this class i'm using constructor that
-(id)InitWithDefaults{
self = [super init];
NSOperationQueue *_queue = [[[NSOperationQueue alloc] init] autorelease];
self.queue = _queue;
[_queue release];
return self;
}
But that line is wrong, bacause i'm using this CommonGateway class a lot of place of my project. When i changed
NSOperationQueue *_queue = [[[NSOperationQueue alloc] init] autorelease];
to
NSOperationQueue *_queue = [[NSOperationQueue alloc] init];
It's working again.
Guys, thank you very much for your support.
精彩评论