cancel
Showing results for 
Search instead for 
Did you mean: 

Question: Dynamic Bitmap Cache and Memory Used

V.H
Senior

Hello all,

I create a custom container in TouchGfxDesigner and I want to used Dynamic Bitmap Cache and Memory:

class Knob : public KnobBase

{

public:

  Knob()

  {

    Bitmap::cache(BITMAP_ENTER_1_ID);

    Bitmap::cache(BITMAP_ENTER_2_ID);

    pbuf = new uint8_t[1024];

  }

  virtual ~Knob()

  {

    Bitmap::cacheRemoveBitmap(BITMAP_ENTER_1_ID);

    Bitmap::cacheRemoveBitmap(BITMAP_ENTER_2_ID);

    delete[] pbuf;

  }

  virtual void initialize();

protected:

  uint8_t *pbuf;

};

I cache bitmap and request memory in constructor and release them in destructor.

Are there any risks in using it here? I've been worrying about memory leaks.

1 REPLY 1
Yoann KLEIN
ST Employee

Hello @V.H​,

Trying to cache stuff inside the constructor and release it in the destructor could work, but it is quite dangerous.

In fact, if you don't know when your Knob class is initialized, in the worst case you could call this function before touchgfx is even instanced.

I would recommend you to cache and de-cache after the construction and before destruction, maybe in the initialize() method, and also to release elsewhere.

Let me know if that helped you,

/Yoann

Yoann KLEIN
ST Software Developer | TouchGFX