Memory consumption of ofImage

ofImage uses too much memory. It allocates around 9 bytes per pixel (at least). It is too much for openGL ES and embedded systems where each bit is important.

One can use an ofImage as a drawable in a 2D scene or as a texture container in a 3D scene. In the drawable case, I see there is an option of “setUseTexture(false)”.

But what I have to do if I only use it for allocating the opengles texture? How I can delete unnecessary image and pixel data after allocating the opengles texture? (Then I will use only getTextureRef() method). Is it possible?

1 Like

For future reference;
Numerous scenarios of loading an ofImage or ofTexture allocates 8-9 bytes per pixel.

The only different scenario I found;

ofTexture texture;
void loadTexture(string filepath) {   
    ofPixels texturepixels; //this is a local variable to be deallocated in the end of the block
    ofLoadImage(texturepixels, filepath);
    texture.loadData(texturepixels.getPixels(), texturepixels.getWidth(), texturepixels.getHeight(), GL_RGBA);

In this case ofTexture allocates the half memory than other cases. (4-4.5 bytes per pixel).

Here are the test results I get:

07-15 08:06:09.483: I/MenuCanvas.cpp(21461): UsedHeap::png 1024x1024::loading ofImage::8398048 bytes
07-15 08:06:09.498: I/MenuCanvas.cpp(21461): UsedHeap::png 1024x1024::loading ofTexture::4199624 bytes

you can do:


where tex is an ofTexture and avoid using ofPixels at all