0
votes

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?

1
Can you provide more details on what you are trying to do?pgb
This is very close to duplicating the question just asked here: stackoverflow.com/questions/867945/memory-issue-in-iphoneBrad Larson

1 Answers

2
votes

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.