Hindu
Hindu

Reputation: 2924

ARC + Dealloc is not called

I am little confuse because my dealloc is not called in ARC. I have using storyboard in my application.

Case 1: Mydealloc called when i use all IBOutlet from storyboard

Case 2: My dealloc is not called when i try to use alloc and init methods in UIViewController. such as below.

 UIViewController *vc = [[UIViewController alloc] initWithNibName:@"ProfileDetailView" bundle:nil];
        __weak ProfileDetailView *detailview = (ProfileDetailView *)vc.view;
        detailview.backgroundColor = [UIColor clearColor];
        vc = nil;
....Set value in object.....

[self.view addSubview:detailview];;
        detailview = nil;

Can you explain why dealloc is not called? and How can i able to achieve to call dealloc?

Thanks

Upvotes: 0

Views: 401

Answers (2)

Hindu
Hindu

Reputation: 2924

Thanks for your reply. I am able to called my dealloc function when view controller pop. For achieving that, we need to remove my added subviews from my view when user tapped on back button.

Upvotes: 0

Vatsal
Vatsal

Reputation: 18191

The concept of ARC is that an object's retain count should theoretically be 1 in order for it to be deallocated. When you execute:

[self.view addSubview:detailview];;

Your self.view increments detailview's retain count by 1 when it adds it to view.subviews. Logically, when self.view removes detailview, the retain count is decremented by 1.

Again, this is a theoretical perspective. The reality is usually:

INSANE.

No one really knows how the mysterious Objective-C runtime works! (just kidding the whole source code is available online.)

Upvotes: 1

Related Questions