Search code examples
iosmemory-leaksxcode-instruments

question regarding memory leak detection on instruments


I am using the instrument provided with XCode 4.3 to detect memory leaks. I am getting a memory leak in the following code line. Not sure why !

 self.view.backgroundColor=[[UIColor alloc] initWithPatternImage:[UIImage imageNamed:@"background-non-retina.png"]];

Can anyone kindly tell me what I am doing wrong here ?

Thanks


Solution

  • backgroundColor=[[UIColoralloc] init...

    Look carefully where it says alloc. Anything you alloc, init, or new you are required to release. Try using an autoreleased color, such as this:

    self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"background-non-retina.png"]];