我在这段代码中遇到内存泄漏问题:
UIImage myImage1 = [[UIImage alloc]
initWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:strimg1]]];
我该如何解决这个问题? 提前谢谢。
答案 0 :(得分:1)
UIImage *myImage1 = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:@""]]];
UIImageView *myimg=[[UIImageView alloc] initWithImage:myImage1];
[self.view addSubview:myimg];
[myimg release];
它可能对你有所帮助。
答案 1 :(得分:0)
请记住,每当使用New或Alloc init创建对象时, 你有责任在dealloc中发布它。并记得使用super dealloc。
确保没有其他物体碰撞保留计数。
init方法中有什么?你是否创建了另一个类UIImage的实例?只是一个想法。
希望这有帮助。 dibu2z