HiDPI high memory usage

Hi,

In HiDPI mode my application consumes a lot of memory, e.g. 1.2GB versus 200MB when HiDPI mode is off.

Why is that?

Thanks,
Payam

We just had this discussion recently
https://forum.xojo.com/44714-macos-high-memory-usage

Every image you create will have 2 levels 2x and 1x so a 100x100 image will have a 200x200 plus a 100x100 image in memory. So your image which was normally taking ~40K in memory is now storing ~200K memory (156 + 40), assuming (100x100x4) / 1024.

This would be the same for the cached os level user controls.

I was caching a lot of thumbnail images and had to push to external memory to avoid 3gig memory limits.

I understand that HiDPI demands more resources, but it should not take excessive dimensions like that in an app that used 100 times less memory without HiDPI.

Will this situation change in the next releases of Xojo?

I thought you said it took 200megs without hidpi. 1.2 gigs is only 6 times more, which is very close to the changes i said.

The other thread mentioned os level caching. Not much you or xojo can do about that.

Remember that a @2x picture contains 4x the pixels, thus requiring 4x the memory. You may also find that internally it will align the data to 16-byte blocks, so there can be some wasted space there (but for optimisation purposes).

Just you wait until you start working with 128-Bit images, where each pixel uses 4x the memory than a typical 8-bit / 32-Bit per pixel image.

Edit: When you load an image via declares you have the option to cache it into memory at full resolution, but the OS will also cache it at the sizes you draw the image at. So one image could easily have several resized versions all stored in memory.

If you’re running on the Mac, you also have display caches. One for the screen, one for each window and one for each control. On a retina screen, each ‘cache’ is ( ( width * 2 ) * ( height * 2 ) ) * 4.

If you have a 27" iMac with a P3 display, then the OS is actually using 10-Bit per channel, which then amounts to 40-Bits per pixel (1-extra byte per pixel). Makeing the equation ( ( width * 2 ) * ( height * 2 ) ) * 5.

For arguments sake you have a HD display, with a window filling the usable area and it has a one single canvas filling the window.
( screenCache = 33 MB, WindowCache = 28 MB, canvasCache = 28 MB ) = 91 MB

With a P3 Display.
( screenCache = 41 MB, windowCache = 35 MB, canvasCache = 35 MB ) = 111 MB

What I don’t know for sure, is if this is stored in the GPU only or the window & control cache is also stored in your application memory (it should be stored in the GPU at least).

Edit 2: Typos, for which there are many of…