views:

57

answers:

2

I have a UIView which I create programmatically roughly like so:

@implementation SlideShowView
- (id)initWithImages
{
    …
    if (self=[super initWithFrame:CGRectMake(0, 0, 320, 480)])
    {
        // init objects here
    }
    return self;
}
- (void)dealloc
{
    printf("dealloc slide show view\n");
    [[NSNotificationCenter defaultCenter] removeObserver:self name:@"unlockUI" object:nil ];
    [[NSNotificationCenter defaultCenter] removeObserver:self name:@"setUserRating" object:nil ];
    [mCurrentImageView release];
    [mRightImageView release];
    [mLeftImageView release];
    [mImages release];
    [queue cancelAllOperations];
    [queue release];
    [managingArray release];
    [super dealloc];
}

with a uiview controller that contains this:

- (void)loadView {
{
    ...
    self.view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
    self.slideShowViewObject = [[SlideShowView alloc] initWithImages];
    [self.view addSubview:slideShowViewObject];
    …
}
-(void)dealloc
{
    [slideShowViewObject release];
    [self.slideShowViewObject removeFromSuperview];
    printf("dealloc of slideshow view controller\n");
    [super dealloc];
}

this seems to be able to dealloc both the view controller and view but when I push this view controller back onto the stack I get the message with zombie enabled: -[SlideShowView retain]: message sent to deallocated instance 0x43ab160

should the alloc not be creating a new instance of the view when the controller is pushed? I don't understand and after spending many hours reading through other posts as well as looking at memory guides I would say I'm thoroughly stumped! Can someone offer any pointers? I only posted the code I deemed necessary but I can post more if need be. Thanks so much!

+1  A: 

First, you shouldn't call both [super init] and [super initWithFrame:], only one of the two in your UIView subclass.

Secondly, you should only set self.view in a view controller in the -loadView method, which is designed for you to create your views. Normally, unless you need to do certain types of setup such as initializing variables, etc, you shouldn't need to override -init in UIViewController subclasses.

chpwn
thank you for the response. I have made those edits to my code as well as the post above. I still have the same problem though. Might you possibly have any other suggestions?
Dobler
A: 

finally, after finagling with the code again tonight I finally got it working. The key piece I was not releasing appears to be

[self.view release];

I suppose this makes perfect sense since I was adding the view as a subview of this alloc'd self view, but I had tried this before. Perhaps cleaning up the code is what made it work this time.

Dobler