Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

mycompuser

macrumors member
Original poster
May 8, 2012
37
0
Hi All,

I am developing an iOS app which is ARC enabled.

When I ran the Instruments tool (Leaks), found that the like containing "imageNamed" method as causing memory leak.

Here is the code snippet.
Code:
in .h file
@property (nonatomic) IBOutlet UIImageView *myImg;
in .m
self.myImg.image = [UIImage imageNamed:@"someImage.png"];//causing memory leak

Similarly this code was also indicating an memory leak.

Code:
.h
@property (nonatomic) UIImage *iPanel;

.m
self.iPanel = [[UIImage imageNamed:@"someImage.png"] resizableImageWithCapInsets:edgeInset];

I read from few links that imageNamed method can cause memory leak issues.

But for some reasons (nearing a major release) I dont want to change imageNamed with imageWithContentsOfFile.

Found another link which says that if you use "strong" (retain's equivalent) will fix this issue.

Need expert's opening on this.

Will changing the property declaration from (nonatomic) to (nonatomic, strong) fix the memory leak issue?
 
You should always declare how the property is meant to behave in terms of memory, it matters!

A quick and dirty is to declare them as strong. Your IBOutlet is likely to be assign though.
 
You should always declare how the property is meant to behave in terms of memory, it matters!

A quick and dirty is to declare them as strong. Your IBOutlet is likely to be assign though.

Or in the case of ios 6 and up it would be a weak property.
 
Guys, Thanks for the reply.

You mean that for IBOutlet, the property need not be changed and let it remain as weak as it is an IBOutlet?

(And for the former case, I can define the property to be strong to avoid the memory leak issue?)
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.