How to free up memory in ARC for rendering graphics with high memory?

First of all, thanks to everyone on this site ... it was NECESSARY to help access iOS programming.

My current problem is:

I have an application that displays a very stylized version of a photo. It uses some CoreImage filters for some of them, but a bunch of CoreGraphics is required to get heavy image processing.

The size of the proxy server looks great, but when rendering the full image of my image, it sometimes crashes due to high memory usage. The problem is that when rendering, I need to have several buffers with full resolution (3264x2448). I do not know what and how to free up more memory. I was very careful about CGImageRelease wherever I can.

And with ARC, how do I know if something is really released and released? Setting the object to nil really does nothing.

And I doubt that I can somehow transfer this to disk.

ANY suggestions will be much appreciated!

THANKS!

+4
source share
3 answers

ARC does not affect this context.

It just means that you do not need to call release yourself.

With non-ARC, in low memory conditions, you might want to release some properties that you really don't need (which means that they can be recreated on demand).

 - ( void )didReceiveMemoryWarning: { [ _myProperty release ]; _myProperty = nil; [ super didReceiveMemoryWarning ]; } 

In ARC, this is exactly the same, except that you do not need to call release :

 - ( void )didReceiveMemoryWarning: { _myProperty = nil; [ super didReceiveMemoryWarning ]; } 

Setting your property to nil will, under ARC, automatically release it.
So it really does something.

If this does not work for you, then you have one more problem.
Make sure you do not have memory leaks, but keep cycles .

The latter is definitely a problem ...

+8
source

So, as suggested (but not explicitly stated) - this is not an ARC problem.

You will need 30 MB to store one image in memory of this resolution (3264x2448, assuming 32 bits per pixel). And until you say how many buffers of this size you need in memory, it sounds at least three - you are mostly limited in memory for many iOS devices (the original iPad and iPhone 3GS have only 256 MB in total because of this there can only be a third access. The memory available to your application has been greatly changed).

ARC is not like garbage collection - it just adds release and retain to release . If you structure your code correctly, your images will be released when they are no longer needed. I strongly suspect that if you disabled ARC (which you can do in a file by file using the compiler flag), you will see the same results.

As someone already wrote, the way around this is to draw your image and work with a small sample at a time. If your blur algorithm can't handle this, then the tough truth is that you probably have to write what it does!

+2
source

You must tiled your image and work only in parts at a time. You can do this by creating CIImage and then calling:

 [myContext drawImage:myImage atPoint:P fromRect:tileBounds]; 

tileBounds and modifying P and tileBounds to eventually cover the entire area of ​​the output image.

0
source

Source: https://habr.com/ru/post/1393818/


All Articles