Double buffering and memory consumption
Posted on January 14, 2021
Each Bee Mobile control which is inherited from BeeMobile.Common.DoubleBufferingControl (and that is the case for majority of them) uses 3 bitmaps to speed up the drawing.
One is used for purpose of double-buffering, which prevents flickering during redrawing the surface of the control and holds the appearance of the control. It also speeds up drawing, if the appearance of the control is unchanged since the last drawing.
The second bitmap is used to cache the background. Since Bee Mobile controls support opacity (independently for their background and foreground), this is useful to speed up the redrawing process, if the background layer of the actual control was not changed, but the translucent underlying control changes its appearance.
The third bitmap is for caching the foreground. This is useful, because foreground has an independent opacity setting as the background. It helps to speed up the drawing, if the foreground stays unchanged, but the translucent background layer or the underlying control changes its appearance.
By default these bitmaps are held in the memory during the lifetime of the control. These back buffers are only created if necessary. If for example the the surface of the control is fully opaque, the back buffer won”t be created. Larger controls (in the terms of size: width x height) can require higher amount of memory due to this fact. Such controls are usually TabPages in TabControls, TouchLists or TransparentPanels. We introduced three properties in Bee Mobile controls to provide the possibility to fine tune the bitmap caching of the controls. These propeties are:
- CacheBackground
- CacheForeground
- CacheControlBuffer
The properties state whether to preserve the cache for each layer. If caching is disabled and the control redraws itself, it has to create the bitmap for the particular layers, but it also drops them after the drawing process. It’s a compromise between memory consumption and speed. If you experience memory consumption issue, you should experiment with these properties to find the ideal trade-off between the speed and memory consumption. For larger controls, which do not change their appearance very often, like TabPages in TabControl, TransparentPanel and TPictureBox, disabling the caching may be a good idea. If you want further speed improvements and reduce memory consumption, try to set the opacity of all controls to 100%.