# Singleton instance

**URL:** <https://forum.juce.com/t/singleton-instance/5518>\
**Category:** General JUCE discussion\
**Created:** [July 29, 2010, 11:18am UTC](https://forum.juce.com/t/singleton-instance/5518 "2010-07-29T11:18:25Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![solar3d](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/solar3d/32/135_2.png) [@solar3d](https://forum.juce.com/u/solar3d)\
**Post date:** [July 29, 2010, 11:18am UTC](https://forum.juce.com/t/singleton-instance/5518/1 "2010-07-29T11:18:25Z")

</div>

Hi All,

I have something where I need your help. It is probably more related to C++ than juce but  
makes me feel stupid.

In my plugin I made the Audioprocessor (so called “myFilter”)a singleton. The plugin has a physical Midi input from where I  
receive Midi controller messages. These messages get processed internaly and then I have to call  
setParameterNotifyingHost to inform the host about the parameter changes. Since the audioprocessor  
is a singleton, I use myFilter::getInstance() to get its pointer but it always creates a new instance  
of myFilter (I think so because the constructor gets called).  
Is this because the Midi input thread is not the message thread and would

const MessageManagerLock mmLock

be the the right way?

Thank you for providing some light here!

Joerg

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [July 29, 2010, 11:30am UTC](https://forum.juce.com/t/singleton-instance/5518/2 "2010-07-29T11:30:16Z")

</div>

Agh! No, a plugin can’t be a singleton!! There obviously need to be multiple instances of a plugin, and you never create or delete these objects yourself - leave it to the wrapper!

In fact, I’d recommend avoiding singletons, statics or any type of global data in plugins if possible. It’s possible, of course, but you need to be very careful and aware of threading issues when you share stuff between plugin instances.

---

<div class="post-metadata">

**Author:** ![solar3d](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/solar3d/32/135_2.png) [@solar3d](https://forum.juce.com/u/solar3d)\
**Post date:** [July 29, 2010, 12:32pm UTC](https://forum.juce.com/t/singleton-instance/5518/3 "2010-07-29T12:32:49Z")

</div>

Thank you Jules, I’ll follow your route…

Joerg
