问题描述
在使用 ObjectAlloc进行仪器调试时,我注意到为renderInContext调用分配了7兆的内存,但从未释放过。当我注释掉renderInContext调用时,不会发生这种情况,以后的renderInContext调用也不会继续增加内存分配。
While debugging in instruments using 'ObjectAlloc' I'm noticing 7megs of memory being allocated for the renderInContext call, but it never is released. When I comment out the renderInContext call this doesn't happen, and future renderInContext calls does not continue to increase the memory allotment.
UIGraphicsBeginImageContext(contentHolder.bounds.size);
[contentHolder.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
是否有一种方法可以强制释放此内存?
Is there a way to force this memory to be released?
推荐答案
我发现了如何释放renderInContext内存。只需在主线程上运行调用renderInContext的方法,该方法将自动释放分配的内存。
I found out how to release the renderInContext memory. Simply run the method calling renderInContext on Main Thread and that will release the allocated memory automatically.
这篇关于renderInContext创建未及时释放的内存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!