1

We used below code to set image in image view,

@autoreleasepool {
    UIImageView *titleView = [[UIImageView alloc] initWithImage:[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"ImgTitle" ofType:@"png"]]];
    }

Instruments shows memory leak in above two lines. We checked through Xcode 5.0.1 to iOS7.

Anyone please suggest to resolve that issue.

Qantas 94 Heavy
  • 15,750
  • 31
  • 68
  • 83
MobDevUser
  • 21
  • 3

2 Answers2

0

Try to change

@autoreleasepool
{
UIImageView *titleView = [[UIImageView alloc]initWithImage:
                         [UIImage imageWithContentsOfFile:
                         [[NSBundle mainBundle]pathForResource:
                         @"ImgTitle" ofType:@"png"]]];
}

to

UIImageView *titleView = [[UIImageView alloc]initWithImage:
                             [UIImage imageWithContentsOfFile:
                             [[NSBundle mainBundle]pathForResource:
                             @"ImgTitle" ofType:@"png"]]];

After using the titleView you can set it to nil to handle memory as below.

If project is ARC enabled, use

titleView=nil;

If not,

titleView release];
titleView=nil;`

This will solve your problem.

svrushal
  • 1,612
  • 14
  • 25
0

For me your code is showing

Dead Store : Value stored to 'titleView' during its initialization is never read

Which makes sense too. There is no memory leak warning

Inder Kumar Rathore
  • 39,458
  • 17
  • 135
  • 184