如何在我的iPhone应用程序中释放这些资源?

时间:2023-01-13 12:40:36

Okay, I have an app that tells me what color of pixel I touched by reading the screen (like a screenshot) after each touch. To retrieve the pixels, I use a method similar to that appearing here. But it seems that after each touch, the image data is still being held on to (and not to mention saving hundreds of unwanted screenshots in my photo album by the way) and I start getting memory notifications shortly before the app finally crashes.... My app starts out at 3.5MB but after each touch this figure increases until it is at about 100MB, after which the app crashes.

好的,我有一个应用程序告诉我每次触摸后通过阅读屏幕(如屏幕截图)触摸的像素颜色。要检索像素,我使用类似于此处出现的方法。但似乎在每次触摸后,图像数据仍然被保留(并且更不用说在我的相册中保存数百个不需要的屏幕截图)并且我在应用程序最终崩溃之前不久开始获取内存通知...我的应用程序从3.5MB开始,但每次触摸后这个数字会增加,直到大约100MB,然后应用程序崩溃。

QUESTION:
How do I free this data after each touch?
(Here is the link again for Source)

问题:每次触摸后如何释放这些数据? (这是Source的链接)

1 个解决方案

#1


The provided code frees all its buffers. The memory leak must be elsewhere.

提供的代码释放所有缓冲区。内存泄漏必须在其他地方。

If you want to use a more streamlined way of reading one pixel's color, you could consider the approach suggested in this answer. The idea is to use a very small buffer and draw the view with a transform that shifts the pixel into the range covered by the context.

如果您想使用更简化的方式读取一个像素的颜色,您可以考虑这个答案中建议的方法。我们的想法是使用一个非常小的缓冲区,并使用一个转换来绘制视图,该转换将像素移动到上下文所覆盖的范围内。

#1


The provided code frees all its buffers. The memory leak must be elsewhere.

提供的代码释放所有缓冲区。内存泄漏必须在其他地方。

If you want to use a more streamlined way of reading one pixel's color, you could consider the approach suggested in this answer. The idea is to use a very small buffer and draw the view with a transform that shifts the pixel into the range covered by the context.

如果您想使用更简化的方式读取一个像素的颜色,您可以考虑这个答案中建议的方法。我们的想法是使用一个非常小的缓冲区,并使用一个转换来绘制视图,该转换将像素移动到上下文所覆盖的范围内。