1
votes

I have a not usual architecture. With one UIViewController and many subview's. I use UIView like viewController and UIViewController for transition animation.

UIView with many subview, which i push on main window, i removeFromSuperview and all ok, but subview not call dealloc method. Also i try to clean objects

- (void) dealloc {
    NSLog(@"ActivityShowVC dealloc");
    [showView removeFromSuperview];
    showView = nil;
}

This called.

- (void) dealloc {
    NSLog(@"ActivityShowView dealloc");

    [mainScroll removeFromSuperview];

    [titleView setDelegate:nil];
    [titleView removeFromSuperview];
    titleView = nil;

    [photoView setDelegate:nil];
    [photoView removeFromSuperview];
    photoView = nil;

    [predictionView setDelegate:nil];
    [predictionView removeFromSuperview];
    predictionView = nil;

    [calendarView setDelegate:nil];
    [calendarView removeFromSuperview];
    calendarView = nil;

    [descriptionView setDelegate:nil];
    [descriptionView removeFromSuperview];
    descriptionView = nil;
}

But this have some problem.

2
Where did you define dealloc? - ldindu
As far as I know you don't have to worry abour remove subviews from superview in dealloc method. All superview will be removed and deallocated when your superview will be deallocated. Just leave delegate = nil in your dealloc method. ARC should take care about the rest. - Greg
i solved it. Problem was in delegate, which keep my views! - outfoll

2 Answers

5
votes

If dealloc is implemented and not called then there is something retaining the instance. You need to rethink the strong references to it.

Dealloc is not a good place to do anything other than releasing resources since the instance is no longer fully functional nor in a complete state. Doing things like: [showView removeFromSuperview]; are best done explicitly prior to deallocation.

As @Greg stated, most or all of what you are doing in dealloc is not needed under ARC. Subviews are now generally weak so no explicit dealloc is necessary. In fact they may be already gone depending on the order of the teardown of the view hierarchy.

2
votes

I have solved a similar problem. In my Viewcontroller, I have a NSTimer pointer created, when I put the code below in 'viewWillDisappear', 'dealloc' is called.

if (_timer) {
        [_timer invalidate];
        _timer = nil;
    }