# Strange memory leak from MessagManager

**URL:** <https://forum.juce.com/t/strange-memory-leak-from-messagmanager/31888>\
**Category:** General JUCE discussion\
**Created:** [February 21, 2019, 7:06am UTC](https://forum.juce.com/t/strange-memory-leak-from-messagmanager/31888 "2019-02-21T07:06:40Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![DidiP](https://avatars.discourse-cdn.com/v4/letter/d/d78d45/32.png) [@DidiP](https://forum.juce.com/u/DidiP)\
**Post date:** [February 21, 2019, 7:06am UTC](https://forum.juce.com/t/strange-memory-leak-from-messagmanager/31888/1 "2019-02-21T07:06:40Z")

</div>

Hello, when trying to load a plugin using this code:

```
    OwnedArray<PluginDescription> pluginDescriptions;
    KnownPluginList pluginList;
    AudioPluginFormatManager pluginFormatManager;
    
    pluginFormatManager.addDefaultFormats();
    
    for (int i = pluginFormatManager.getNumFormats(); --i >= 0;)
    {
        pluginList.scanAndAddFile (String (path),
                                   true,
                                   pluginDescriptions,
                                   *pluginFormatManager.getFormat(i));
    }

```

I get:  
\*\*\*\*\* Leaked objects detected: 1 instance(s) of class MessageManager\*\*

**JUCE Assertion failure in juce\_LeakedObjectDetector.h:90**

Does someone know what can be the problem? Thanks!

---

<div class="post-metadata">

**Author:** ![daniel](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/daniel/32/790_2.png) [@daniel](https://forum.juce.com/u/daniel)\
**Post date:** [February 21, 2019, 9:43am UTC](https://forum.juce.com/t/strange-memory-leak-from-messagmanager/31888/2 "2019-02-21T09:43:29Z")

</div>

Are you trying this without a GUI?  
The MessageManager is a singleton, in a GUI app it will be destroyed automatically.  
In a console app or anything, that doesn’t call the [JUCE\_START\_APPLICATION (MyApp)](https://docs.juce.com/develop/group __juce__ events-messages.html#ga10c79cf9cafd40244a741e5945878e79) macro,  
you have to add a [ScopedJuceInitialiser\_\_GUI](https://docs.juce.com/develop/classScopedJuceInitialiser__GUI.html), that will clean up when going out of scope.

Hope that helps.

---

<div class="post-metadata">

**Author:** ![DidiP](https://avatars.discourse-cdn.com/v4/letter/d/d78d45/32.png) [@DidiP](https://forum.juce.com/u/DidiP)\
**Post date:** [February 21, 2019, 11:57am UTC](https://forum.juce.com/t/strange-memory-leak-from-messagmanager/31888/3 "2019-02-21T11:57:46Z")

</div>

Thank you Daniel, it helps!
