将UIview转换为导致内存泄漏的UIimage [英] Converting an UIview unto UIimage causing memory leak

查看:153
本文介绍了将UIview转换为导致内存泄漏的UIimage的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用coverFlow视图为iPhone开发应用程序,当应用程序正在构建卡时,它正在使用UIView来添加标签和其他内容。然后我使用以下代码将UIView转换为UIImage:

I'm developing an app for iPhone using a coverFlow view, when the app is building the cards it is using a UIView in order to add labels and other stuff. Then I convert the UIView into UIImage using the following code:

UIGraphicsBeginImageContext(imageView.bounds.size);
[imageView.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

// returning the UIImage
return viewImage;

每次重绘封面流量时,我都有大量的内存分配增量,即使我dealloc也不会减少我的coverFlow视图。

Every Time I redraw the coverflow I have a huge memory allocation increment, that never decreases even if I dealloc my coverFlow view.

我认为内存泄漏在我添加的代码中,你怎么看?

I think the memory leak is in the code that I added, what do you think?

推荐答案

您提供的代码段中没有明显的内存泄漏。由于 UIGraphicsBeginImageContext(),无法在后台线程上执行该操作,因此您应该有一个 NSAutoreleasePool UIGraphicsGetImageFromCurrentContext()的返回值是自动释放的)。如果没有进一步的信息,就无法分辨出内存泄漏的位置 - 我建议你查看最终拥有viewImage对象的任何对象,并确保在保留它的情况下正确释放UIImage。

There is no memory leak apparent in the code snippet you provided. That operation could not be performed on a background thread because of UIGraphicsBeginImageContext(), so you should have an NSAutoreleasePool in place (the return value of UIGraphicsGetImageFromCurrentContext() is autoreleased). Without further information, its impossible to tell where the memory leak could be - I suggest you look at whatever objects eventually own the viewImage object and make sure you are properly releasing the UIImage if you retain it.

这篇关于将UIview转换为导致内存泄漏的UIimage的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆