Images use a lot of ram in a fast app

My application uses 95MB of RAM, when I did some research with the tools, I found that CoreUI Image Date uses 70MB, how to reduce this usage?

+3


source to share


1 answer


There are several considerations:

  • The only image objects that need to be created are those currently displayed on the screen. Don't keep images in an array. (You can use a cache for performance reasons, but clear that cache under memory pressure.) Of course, you have an array of image filenames (or ids or whatever you have), but not the images themselves.

    For example, you want to make sure that you dynamically instantiate images as needed (for example, when they preview the view) and release them when they become more visible (for example, when they scroll out of sight).

  • If the dimensions of the images are larger than the dimensions of the representations of the images (adjusted for the display scale), these images should be resized accordingly. The amount of memory consumed depends on the size of the image, not on the image. For example, a 100x100 image would take 40kb, but a 1000x1000 image would take 4MB.



These two points are relevant because images often require much more memory than the file size of the original assets can suggest. Runtime memory usage is a function of image sizes, not file size. Image files are usually compressed, but uncompressed when used by an application. The memory used at run time is often 4 times the width of the image, significantly more than the amount of space used by the original JPG or PNG file.

+4


source







All Articles