Memory leak caused by getFont() and WindowsDirectWriteTypeFace

I am going throught the JUCE course made by Outptut and I have come across a memory leak which I can’t find a good way to solve. Basically I have a .h file called “Interface Defines” where I store all the constants used in the painting of the UI. These include 3 juce fonts.

const juce::Font font_1(“Arial”, 12.00f, juce::Font::bold);
const juce::Font font_2(“Arial”, 22.00f, juce::Font::bold);
const juce::Font font_3(“Arial”, 48.00f, juce::Font::bold);

I then use these in a custom LookAndFeelClass:

juce::Font getLabelFont(juce::Label& label) override
return font_1;


juce::Font getTextButtonFont(juce::TextButton&, int buttonHeight) override
return font_1;

These functions are overriden from LookAndFeelV4. The plugin runs fine until I close it, at which point I get a jassertfalse and an error message which reads

*** Leaked objects detected: 1 instance(s) of class WindowsDirectWriteTypeface

I have tracked down the problem to these two functions. If i declare font_1 as a member of my custom look and feel then it all works fine but I need to be able to access the fonts from other classes. For example in one of my components I call


for a piece of text which also causes the the assertion to trip. I have tried to use std::unique_ptr for the font declarations but the problem persists. I’m wondering if this is just a bug inside juce.

I think the problem stems from the fact these functions dont get references or pointers, they copy the whole object. My question is: is there any way to keep these const Fonts in a seperate file without hitting a memory leak.