Memory leaks

Hi guys :slight_smile:

I’m not an expert on coding and i’m starting studying c++ and juce

I modified the example project i found in juce\extras\example projects.

I only added these lines to the paint function

TextEditor* textEditor = new TextEditor();
addAndMakeVisible(textEditor);
textEditor->setBounds (10, 25, 200, 24);
textEditor->setText (T("Write Something!"));

And I get memory leaks on closing the application.

Why? What’s wrong? :?

Thank you
Francesco

The lines should go in the constructor. And then you need a corresponding delete statement in the destructor.

If you put it in the paint function you create a new componenet every time the component is redrawn.

Thank you!

It was so simple :frowning: