Android Question Canvas Memory Usage

Gary Milne

Active Member
Licensed User
Longtime User
From what I have read a canvas allocates memory when it is initialized that is equivalent to:

Canvas Width * Canvas Height * 4bytes - On a Nexus 7 this would be 1920 * 1280 * 4 = 9.8Mb​

If I load a 1Mb PNG file into the canvas, does the canvas object use 9.8Mb or 1Mb of memory.



B4X founder
Staff member
Licensed User
Longtime User
Canvas draws on a mutable bitmap that it implicitly creates (assuming that you are not using Canvas.Initialize2).
The memory required is approximately Width * Height * 4 bytes.

This is also true for bitmaps that you load. When you load an image file the memory required depends on the width and height of the image.

The canvas itself will always consume the same memory. You can draw 1000 bitmaps with Canvas.DrawBitmap and the canvas memory usage will be the same.
Upvote 0