Reputation: 1607
1.UIImageView *img1=[[UIImageView alloc]initwithImage:[UIImage imageNamed:@"1.png"]];
2.UIImageView *img2=[[UIImageView alloc]initwithImage:[UIImage imageNamed:@"2.png"]];
a) img1.image = [UIImage imageNamed:@"2.png"];
b) [img1 setImage:img2];
which way utilizes minimum memory among a and b?why?
if i need to do this multiple times which way you suggest?
Upvotes: 0
Views: 120
Reputation: 18497
b) Because you are creating a reference to an existing object, but they will both point to "2.png" In a) you are creating a new instance of an object which coincidentally happens to point to the same file, but it is allocated as separate memory space.
Upvotes: 2