Iphone imageview中的内存泄漏

Iphone imageview中的内存泄漏,iphone,memory-leaks,Iphone,Memory Leaks,我在以下代码中遇到内存泄漏问题: UIImage myImage1 = [[UIImage alloc] initWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:strimg1]]]; 我怎样才能解决这个问题? 提前谢谢 UIImage *myImage1 = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:@""]

我在以下代码中遇到内存泄漏问题:

UIImage myImage1 = [[UIImage alloc]
    initWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:strimg1]]];
我怎样才能解决这个问题? 提前谢谢

UIImage *myImage1 = [UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:@""]]];
UIImageView *myimg=[[UIImageView alloc] initWithImage:myImage1];
[self.view addSubview:myimg];
[myimg release];

它可能会对您有所帮助。

请记住,无论何时使用New或Alloc init创建对象, 您有责任在dealloc中发布它。记住使用超级Dealoc

确保没有其他对象碰撞保留计数

init方法中有什么?您是否创建了UIImage类的另一个实例?只是一个想法


希望这有帮助。dibu2z

您可以创建UIImageView类型的变量,然后将其设置为UIImage。类型不匹配,您确定示例正确吗?Twelve47的评论也是如此。Björn Marschollek的回答是不正确的,尽管您确实需要在某个时候发布图像视图,很明显,“*”也丢失了。。。这整件事都不会编译!