« The FileMaker.Perform… | Home | More customization fo… »

Xojo's picture cache

The Xojo picture class internally has several platform dependent implementations with slightly different behaviors. Let's check how the implementations have an effect on memory consumption.

On MacOS the picture class implementation for an editable picture uses both a CGBitmapContext for the pixels and a CGImage for drawing it. So the pixels are hold in a CGBitmapContext for the actual picture. If the picture has a mask, there is a second CGBitmapContext for the mask, which doubles the memory usage.

When the picture is drawn or some plugin function requests a CGImage for the picture, Xojo will create one and cache it. The CGImage consumes about the same memory size as the normal picture part. And the cache stays there after the drawing for the case of another draw command. But the cache is invalidated and freed, when the graphics of the picture is used. You can clear the cache for example with the following call:

Dim g as graphics = pic.graphics
g.drawline -100, -100, -10, -10

This frees the memory for the cache and does not draw something as the coordinates are negative.

Usually you may never need to do this, but if you load a lot of images, keep them in array and draw them into smaller ones, you may need a lot of memory, so clearing the cache may be good, especially for a 32-bit application, where memory is tight. But usually it may be better to just clear last reference to picture early when you don't need the big picture any more.

First tests on Windows seem to indicate that on Windows for DirectDraw Xojo also uses a similar system as drawing as memory usage goes up when you draw a picture into another one.
26 05 20 - 07:54