WindowsMidiService Leak

Hi !

When I open a midiport (with a scopedpointer) I have a leak and I don’t understand why. When I using the following code :

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

The port work, I can send midi events. But when the application end, there is this leak. When I try to open severals ports with scopedpointers, still there is one instance of WindowsMidiService that leaked …

So if I missed something I hope someone could tell me :slight_smile:

I’ve never used it, but I guess it’s because your program is not supposed to destroy a MidiOutput.

Just don’t return a ScopedPointer<MidiOutput> but just a regular pointer MidiOutput*. But then again, I’ve never used it, so not sure if it works :slight_smile:

Edit: To make sense of it: a ScopedPointer will destroy the object when it goes out of scope. That’s what happens when your main() function ends.

Yes I already try to not delete it. But it s worst cause when I use severals midioutputs and not delete them I have the same number of leaked objects. But when I use scopedpointers I only have one ^^’

Edit : thanks for your answer anyway :slight_smile:

I just read the doc again, apparently you should delete it, so the ScopedPointer approach isn’t so bad at all :wink: My bad!

The MIDI system creates singleton objects in the background, but you’ve put this call inside a main() function that doesn’t give any of it chance to clean up before the process is killed. See the ScopedJuceInitialiser_GUI class, maybe?

Thanks ! It works :slight_smile:

I just added “ScopedJuceInitialiser_Gui juceInitialiser;” at the top of the main and open ports in the ScopedPointers and no leak anymore :smile: