开发者

Memory Crash due to [super dealloc] of uiview controller

I am having a uiviewcontroller instance and when I am releasing it the dealloc method of it is called.

I have released some objects in dea开发者_如何转开发lloc method of that uiviewcontroller.

If I comment [super dealloc] the app is working fine but if don't it is crashing.

I think there is no problem with the releases that I am doing in that method, but if I do [super dealloc] it is crashing.

Can any one help me out with this?


Hard to tell from your post without more information, but does your dealloc method look like this?

- (void)dealloc {

    [super dealloc];

    self.someProperty = nil;
}

Because if it does, you're calling a setter method on a deallocated instance. You should always call [super dealloc] last:

- (void)dealloc {

    self.someProperty = nil;

    [super dealloc];

}

Not sure if that helps. Try posting what your dealloc method looks like if not. Hard to troubleshoot in the dark.


It's not possible to help you without more information. The code you described is perfectly fine. The problem is in some other part of your app.

You probably access the view controller after releasing it, so the problem is not the [super dealloc] but any other place in you application that accesses the view controller.


Maybe you are releasing the controller in the wrong place. That could be why your [super dealloc] in your ViewController.m is crashing

You shouldn't called [viewController release] until you want that controller to die. For example, if you have an application with just a viewcontroller you must not release it until the application ends. This is because that controller needs to stay alive all the time to control the view. If you have in your ApplicationDelegate something like this, it will crash:

- (void)applicationDidFinishLaunching:(UIApplication *)application {
UIViewController *controller = [[UIViewController alloc] init];
[window addSubview:controller.view];
[controller release]; //this will crash
}

Instead of that you should place your viewcontroller in the header file (.h) and release it in the dealloc method:

- (void)dealloc {
[controller release];
[window release];
[super dealloc];
}

I hope this helps.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜