views:

18

answers:

1

Hi!

I have a simple UIViewController derived class. Which shows a simple UIImageView. Now the problem is that when I load this view controller using [NSBundle loadNibNamed.. method and then try and access its view using

viewController.view the reference count of both controller and view go up by 29. Later on when I release this viewController, i still see a retain count of 5.

When I analyze my code in Instruments it shows a memory leak.

Any hints are welcome? As per instruments there is leak in line 2 and line 8 of the following code.

ABCViewController *aViewController = [[ABCViewController alloc] initWithNibName:STR_XIB_NAME_SCREEN_IPHONE bundle:nil];
UIView * currentView = aViewController.view;
[m_appWindow addSubview:currentView];

if (m_CurrentViewController != nil)
{
    //m_CurrentViewController stores the reference to the currentViewController loadedby the application.
 [m_CurrentViewController.view removeFromSuperview];
 [m_CurrentViewController release];
}
m_CurrentViewController = aViewController;
[m_appWindow bringSubviewToFront:currentView];
[m_CurrentViewController retain];
[aViewController release];
A: 

addSubview retains the added view. So after calling

[m_appWindow addSubview:currentView];
this view is retained. Are you removing this anywhere else?

taskinoor
Yes, in the later section of the code I do remove the views. Problem is that even When I simply remove the views instruments continues to show a memory leak.