Basic Question about juce::Image


#1

I have a question about using the juce::Image class. I guess it is both a C++ and a JUCE question.

My application has a background image, that I create programatically. When I resize my application, I create a new image every time, in the “resized()” function.

So I am doing something like this:

void MainTab::resized()
{
   background = Image(Image::RGB, getWidth(), getHeight(), false);
   //Fill the image with some data
   ...
}

class MainTab  : public Component
{
public:
    void resized();
private:
    Image background;
};    

My question is: am I allowed to do so? Every time I resize the window, a new image is craeted. But where will the Images actually be created? On the stack or on the heap?
And what happens to the “old” images? Who is keeping track of them? Am I leaking memory? Do I maybe need to delete them somehow?


'Image', binary resources and dynamic memory
#2

Yes, it’s fine. You’re not leaking, and don’t worry about where the data is stored! It’ll be on the heap, or the GPU, or somewhere. Doesn’t matter!


#3

Hi Jules,
Thanks for the fast reply!