为什么我的图像泄露或变成僵尸?
我有一个可以切换图像的应用程序,但我遇到了很多麻烦...... 第一个“del”是de AppDelegate,“displayImage”在其.m中定义 “equiz”是一个整数,但所有图像都被命名为“1”、“2”等
所以当我使用此代码时,我会发生泄漏,但不会崩溃:
UIImage *img = [UIImage imageNamed:[NSString stringWithFormat:@"%d",equiz]];
UIImageView *imgView = [[UIImageView alloc] initWithImage:img];
imgView.frame = del.displayImage.frame;
del.displayImage = imgView;
[imgView release];
然后我使用这个,但当我转到设备的“桌面”,然后返回应用程序:
UIImage *img = [UIImage imageNamed:[NSString stringWithFormat:@"%d",equiz]];
del.displayImage.image = img;
[img release] //"that line"
然后您说:“您正在释放您不拥有的对象” 我说:“如果我删除“那行”,我会得到同样的泄漏 D:
有人可以帮我解决这个问题吗? 预先非常感谢您:D
I have an app that switches an image, but i get a lot of trouble...
first "del" is de AppDelegate, and "displayImage" is defined in its .m
"equiz" is an integer, but all the images are named "1", "2" and like that
So when i use this code i get leaks but no crash:
UIImage *img = [UIImage imageNamed:[NSString stringWithFormat:@"%d",equiz]];
UIImageView *imgView = [[UIImageView alloc] initWithImage:img];
imgView.frame = del.displayImage.frame;
del.displayImage = imgView;
[imgView release];
Then i use this but i get a crash when i go to the "desktop" of the device, and return to the app:
UIImage *img = [UIImage imageNamed:[NSString stringWithFormat:@"%d",equiz]];
del.displayImage.image = img;
[img release] //"that line"
Then you say: "you are releasing the object that you dont own"
And i say: "If i delete "that line" i'll get the same leak D:
Can someone help me with this issue?
Thank you very much in advance :D
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
嗨,我也遇到了类似的问题,它来自 NSString。所以我的解决方案是这样的:
在 .h 文件中创建,
然后在 .m 文件中执行此操作
@synthesize imageName;
...
...
并在 dealloc 方法中释放 imageName...
对我来说这是有效的..希望帮助也是您的解决方案。
Hi I was have similar problem and it was from NSString. So my solution was this:
in .h file create
then in .m file do this
@synthesize imageName;
...
...
and in dealloc method release imageName...
By me this works .. Hope help is solution for you too.