# Memory Leaks on shutdown

**URL:** <https://forum.juce.com/t/memory-leaks-on-shutdown/60243>\
**Category:** Audio Plugins\
**Created:** [March 1, 2024, 2:46pm UTC](https://forum.juce.com/t/memory-leaks-on-shutdown/60243 "2024-03-01T14:46:16Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![alexrodi](https://avatars.discourse-cdn.com/v4/letter/a/4491bb/32.png) [@alexrodi](https://forum.juce.com/u/alexrodi)\
**Post date:** [March 1, 2024, 2:46pm UTC](https://forum.juce.com/t/memory-leaks-on-shutdown/60243/1 "2024-03-01T14:46:16Z")

</div>

Creating a completely blank plug-in project on ProJucer, I hit several memory leak assertions and finally an assertion in `Singleton` upon closing the DAW.

This _does not_ happen when closing the editor window and then the host, only when the host is closed with the plug-in window open.

```auto
*** Leaked objects detected: 1 instance(s) of class OwnedArray
JUCE Assertion failure in juce_LeakedObjectDetector.h:92

*** Leaked objects detected: 1 instance(s) of class AsyncUpdater
JUCE Assertion failure in juce_LeakedObjectDetector.h:92

JUCE Assertion failure in juce_Singleton.h:50

```

Edit: the full `SingletonHolder` class name that asserts is:

```auto
juce::SingletonHolder<juce::ModalComponentManager, juce::DummyCriticalSection, false>

```

---

<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:** [March 1, 2024, 2:51pm UTC](https://forum.juce.com/t/memory-leaks-on-shutdown/60243/2 "2024-03-01T14:51:48Z")

</div>

A Singleton is a wrapper around a static variable, so it will be destroyed after the leak detector is evaluated.

My best advice is to avoid static included singleton at all cost.

If you still need the Singleton, use the class [DeletedAtShutdown](https://docs.juce.com/master/classDeletedAtShutdown.html):

> So if you’ve got a singleton and don’t want to have to explicitly delete it, just inherit from this and it’ll be taken care of.

---

<div class="post-metadata">

**Author:** ![alexrodi](https://avatars.discourse-cdn.com/v4/letter/a/4491bb/32.png) [@alexrodi](https://forum.juce.com/u/alexrodi)\
**Post date:** [March 1, 2024, 2:57pm UTC](https://forum.juce.com/t/memory-leaks-on-shutdown/60243/4 "2024-03-01T14:57:17Z")

</div>

I think you’re either a bot or you scraped the text a bit too quickly… 🙂

I said:

> Creating a completely blank plug-in project…

So, I wrote exactly 0 characters of code for this to happen.

Also, as a side note, after many years of writing C++ software I’ve literally never needed a singleton object for any application.

---

<div class="post-metadata">

**Author:** ![railjonrogut](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/railjonrogut/32/505_2.png) [@railjonrogut](https://forum.juce.com/u/railjonrogut)\
**Post date:** [March 1, 2024, 3:03pm UTC](https://forum.juce.com/t/memory-leaks-on-shutdown/60243/5 "2024-03-01T15:03:59Z")

</div>

Which JUCE branch and which host?

Rail

---

<div class="post-metadata">

**Author:** ![alexrodi](https://avatars.discourse-cdn.com/v4/letter/a/4491bb/32.png) [@alexrodi](https://forum.juce.com/u/alexrodi)\
**Post date:** [March 1, 2024, 3:06pm UTC](https://forum.juce.com/t/memory-leaks-on-shutdown/60243/6 "2024-03-01T15:06:53Z")

</div>

v 7.0.10 - `master`

Tested on Reaper and Ableton Live with exactly the same behaviour.

---

<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:** [March 1, 2024, 3:09pm UTC](https://forum.juce.com/t/memory-leaks-on-shutdown/60243/7 "2024-03-01T15:09:06Z")

</div>

> [@alexrodi](#):
>
> I think you’re either a bot or you scraped the text a bit too quickly… 🙂

Apologies, I misseedd that.

Could it be you have another plugin loaded?  
Anyway, I didn’t observe that here.

---

<div class="post-metadata">

**Author:** ![alexrodi](https://avatars.discourse-cdn.com/v4/letter/a/4491bb/32.png) [@alexrodi](https://forum.juce.com/u/alexrodi)\
**Post date:** [March 1, 2024, 3:59pm UTC](https://forum.juce.com/t/memory-leaks-on-shutdown/60243/8 "2024-03-01T15:59:07Z")

</div>

Interesting… I actually don’t have any other plug-ins, I started a fresh project and simply opened the blank plug-in, then closed the host with the plug-in window still open.

Btw, I’m on an M1 Mac with JUCE v 7.0.10 on the `master` branch

---

<div class="post-metadata">

**Author:** ![audiothing](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/audiothing/32/8906_2.png) [@audiothing](https://forum.juce.com/u/audiothing)\
**Post date:** [March 5, 2024, 11:26am UTC](https://forum.juce.com/t/memory-leaks-on-shutdown/60243/9 "2024-03-05T11:26:48Z")

</div>

I have the same issue, tested on macOS Sonoma and Monterey, with Reaper 7.03 (AU only, VST3 seems fine).

Steps to replicate:

- compile the GainPlugin demo
- run Reaper in debug
- load GainPlugin (AU)
- close Reaper

```auto
*** Leaked objects detected: 1 instance(s) of class OwnedArray
JUCE Assertion failure in juce_LeakedObjectDetector.h:92

```

I tested this on JUCE 7.0.10 but also on previous JUCE versions (and previous Reaper versions).

---

<div class="post-metadata">

**Author:** ![phraemer](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/phraemer/32/10076_2.png) [@phraemer](https://forum.juce.com/u/phraemer)\
**Post date:** [April 26, 2024, 8:50am UTC](https://forum.juce.com/t/memory-leaks-on-shutdown/60243/10 "2024-04-26T08:50:20Z")

</div>

Same issue since we bumped from an older version to 7.0.12

Only happens with AU project on macOS

---

<div class="post-metadata">

**Author:** ![7sharp9](https://avatars.discourse-cdn.com/v4/letter/7/ccd318/32.png) [@7sharp9](https://forum.juce.com/u/7sharp9)\
**Post date:** [May 27, 2024, 5:50pm UTC](https://forum.juce.com/t/memory-leaks-on-shutdown/60243/11 "2024-05-27T17:50:19Z")

</div>

I hit this today, I added the Heavy memleak detector but it doesnt really give me an idea where its ccoming from other than the ModalComponentManager

---

<div class="post-metadata">

**Author:** ![7sharp9](https://avatars.discourse-cdn.com/v4/letter/7/ccd318/32.png) [@7sharp9](https://forum.juce.com/u/7sharp9)\
**Post date:** [May 30, 2024, 4:19pm UTC](https://forum.juce.com/t/memory-leaks-on-shutdown/60243/12 "2024-05-30T16:19:11Z")

</div>

I confirm the AU fails with a leak of ModalComponentManager but VST3 works ok, this is with Reaper 7.16 and Juce 7.0.12.

Also occcurs with the juce8 branch and the develop branch too

---

<div class="post-metadata">

**Author:** ![7sharp9](https://avatars.discourse-cdn.com/v4/letter/7/ccd318/32.png) [@7sharp9](https://forum.juce.com/u/7sharp9)\
**Post date:** [May 30, 2024, 5:14pm UTC](https://forum.juce.com/t/memory-leaks-on-shutdown/60243/13 "2024-05-30T17:14:15Z")

</div>

I think the key thing is this only occcurs when you leave the plugin window **open** on quitting Reaper, if you close the plugins UI first, there is no leak.

---

<div class="post-metadata">

**Author:** ![reuk](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/reuk/32/21494_2.png) [@reuk](https://forum.juce.com/u/reuk)\
**Post date:** [June 24, 2024, 7:17pm UTC](https://forum.juce.com/t/memory-leaks-on-shutdown/60243/14 "2024-06-24T19:17:08Z")

</div>

Thanks for your patience. A couple of fixes have been added on the develop branch:

> <https://github.com/juce-framework/JUCE/commit/fd01869cfd042d6cc17aeae0f8d5d10716e7c4d7>
>
> The ScopedJuceInitialiser may have been destroyed before shutdown is
> called, in …which case singletons will have been deleted and cleared.
> Attempting to access the ModalComponentManager here will recreate it,
> and will trigger a leak detector warning later on.

> <https://github.com/juce-framework/JUCE/commit/225f1526eecaf225f6b642231ac1f6c6158b97da>

---

<div class="post-metadata">

**Author:** ![7sharp9](https://avatars.discourse-cdn.com/v4/letter/7/ccd318/32.png) [@7sharp9](https://forum.juce.com/u/7sharp9)\
**Post date:** [July 12, 2024, 10:33pm UTC](https://forum.juce.com/t/memory-leaks-on-shutdown/60243/15 "2024-07-12T22:33:51Z")

</div>

Thanks! Did these make it to the Juce 8 release? The reason I ask is Im onnn Juce 8 and still get these. Im not on the develop branch though.

---

<div class="post-metadata">

**Author:** ![attila](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/attila/32/11206_2.png) [@attila](https://forum.juce.com/u/attila)\
**Post date:** [July 15, 2024, 1:08pm UTC](https://forum.juce.com/t/memory-leaks-on-shutdown/60243/16 "2024-07-15T13:08:23Z")

</div>

There has been no versioned release since these fixes were added. These changes will be included as soon as a new point release ships.

---

<div class="post-metadata">

**Author:** ![lalala](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/lalala/32/8577_2.png) [@lalala](https://forum.juce.com/u/lalala)\
**Post date:** [July 18, 2024, 12:23pm UTC](https://forum.juce.com/t/memory-leaks-on-shutdown/60243/17 "2024-07-18T12:23:58Z")

</div>

Any chance we could get an official JUCE 7 branch where this kind of fixes could be cherry picked ?  
Or will there never be any changes/fixes to JUCE 7 anymore?

---

<div class="post-metadata">

**Author:** ![avroshk-2](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/avroshk-2/32/686_2.png) [@avroshk-2](https://forum.juce.com/u/avroshk-2)\
**Post date:** [October 13, 2024, 9:23pm UTC](https://forum.juce.com/t/memory-leaks-on-shutdown/60243/18 "2024-10-13T21:23:37Z")

</div>

> [@7sharp9](#):
>
> ese make it to the Juce 8 release? The reason I ask is Im onnn Juce 8 and still get these. Im not on the develop branch though.

I was able to validate this issue has been resolved on JUCE 8.0.2
