aneuryzm
aneuryzm

Reputation: 64834

Released UIViewController is correctly destroyed but its -(void)dealloc method is not invoked

When I release a UIViewController, the UIViewController is correctly destroyed but its dealloc method is not called.

If the UIViewController has been destroyed (it is nil in the console), then the retain count should be 0, consequently I expect the -(void)dealloc method to be called.

I've also checked for subclasses of my UIViewController, overriding dealloc without calling the superclass method, but this is not the case.

This is how I initialize it:

myViewController = [[MyViewController alloc] initWithViewController:statusPicker];

What could be the reason ? Thanks

Upvotes: 0

Views: 447

Answers (2)

g_fred
g_fred

Reputation: 6018

Check that you haven't got any circular references. For instance if your view controller implements a delegate protocol, check that your code doesn't retain this delegate.

Upvotes: 0

Rui Peres
Rui Peres

Reputation: 25907

If the UIViewController has been destroyed (it is nil in the console), then the retain count should be 0, consequently I expect the -(void)dealloc method to be called.

Well, no. The fact of being nil, doesn't mean the UIViewController has been released. Put it simple, the pointer for the UIViewController, is now pointing to nil, but the memory where the UIViewController reside is still being occupied. Instead of being called dealloc, two things might be happening:

1) There is something else with a reference to the UIViewController (example: when you pushViewController B from A, A got a reference to B).

2) You got a memory leak.

Again I am basing my answer in what you said:

@Lefteris Automatic Referencing Counting = NO

Upvotes: 2

Related Questions