简体   繁体   中英

iphone memory management

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?

b)因为您正在创建对现有对象的引用,但是它们都将指向“ 2.png”。在a)中,您正在创建对象的新实例,该对象恰巧指向同一文件,但是已分配了该文件作为单独的内存空间。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM