## QPix v2.2 | ## Advanced topics

# How QPix handles memory

When working with images memory issues should be taken seriously into account. This is especially important for a database environment like 4D, where insufficient application memory may cause unpredictable behavior — even crashes and loss of data.

How QPix uses memory

QPix allocates memory for the following purposes:

- To hold offscreen buffers for image files displayed in plug-in areas
- To hold temporary copies of picture parameters
- For small in-memory structures that keep track of plug-in areas and graphics importers

The biggest blocks of memory allocated by QPix are due to offscreen buffers. Offscreen buffers speed up drawing, but they can become quite large depending on source image dimensions and color depth.

In QPix v2 offscreen buffers are purgeable. Under low memory conditions the system can purge the offscreen buffers to free up memory. Offscreen buffers are later recreated if needed. This may slow down an application under low memory conditions, but operation is reliable and QPix can handle large images without problem, even with marginal memory sufficiency.

Who else uses memory

Another memory consumption is due to QuickTime and its components that QPix uses internally. Some components are conservative on memory (e.g., the Photoshop importer) but others are not (e.g., the TIFF importer). This difference can be teh result of the complexity of specific formats, of poor implementation of specific components, or of combinations.

Most graphics importers do not allocate their memory from the application memory space, but from the system or from the Mac’s temporary memory (memory that is not used by any running application). This means that 4D’s memory is not the only relevant number; you should always have plenty of RAM even though no software seems to be using it.

Guidelines (or lack thereof)

It is not possible to set up specific memory guidelines for the application and the system, because, as explained, this largely depends on each application and the kind and sizes of images it deals with. The rule is: the more memory, the better.

On MacOS you can test your 4D application with different memory allocations, but always make sure to leave enough free memory for the System because QuickTime will use it.

On Windows memory requirements are somewhat bigger. This is because QuickTime implements much of the MacOS on Windows (a similar thing to what Altura does for 4D). However, on Windows there is less to worry about because the OS uses a flat memory scheme that is quite different from the Mac's Memory Manager. Of course, the general rule applies here too: the more memory, the better.