Pavan
Pavan

Reputation: 18508

instruments: memory leak when creating UIButton

I am trying to find out why when creating an UIButton in interface builder - a memory leak occurs when running the instruments application by xcode.

This is how I created the memory leak.

I opened a new application, opened up the myAppViewController.xib file in interface builder. I changed the background to black. Added a UIButton, renamed it to "foo" title. saved and then exit.

In the myAppViewController.h file i have the following

#import <UIKit/UIKit.h>

@interface miPlanNewViewController : UIViewController { 
    IBOutlet UIButton *tasksProjects; 
}
@property(nonatomic, retain) IBOutlet UIButton *tasksProjects;
@end

in the myAppViewController.m file i have the following:

#import "miPlanNewViewController.h"

@implementation miPlanNewViewController
@synthesize tasksProjects;

...
//the normal methods you get
...
- (void)dealloc {
    [super dealloc];
}
@end

Here is a screen shot of what I am getting at the moment in instruments.

alt text alt text

One thing i notice however....

I haven't connected the Outlet to the uibutton yet in interface builder, BUT when I delete the UIButton from interface builder, save, and then run the program with instruments again, I dont get any sort of leaks at all.

Can someone please explain what is happening and how I can solve this issue. Thank you.

Upvotes: 4

Views: 845

Answers (1)

mackross
mackross

Reputation: 2234

  • Firstly, you're not releasing the property. in dealloc you should have [tasksProjects release]; and in viewDidUnload you should have self.taskProjects = nil;
  • Secondly, as lxt metioned you shouldn't be using the simulator for memory leak checking.
  • Thirdly, check that you're building release not debug.

Upvotes: 2

Related Questions