Memory deallocation when quitting the plugin

Hi all,

my plugin allocates some objects and arrays in memory; all is fine.
If I add new tracks in my host (Cubase 5), each of them connected to a different instance of the plugin, I see memory grow up; but when I delete one track and the associated plugin, the memory does not fall down.

In my plugin memory deallocation occours inside the destructor of the class that inherits AudioProcessor.

How to unload memory when quitting each plugin instance?


Well, if you’ve made sure that you’re not leaking, then your heap is probably getting fragmented so that the runtime can’t shrink it. Not much that can be done about that, I’m afraid!


look at this code:

MyClass*** myVar;

myVar = new MyClass**[N];

for(int n=0; n<N; n++) {
  myVar[n] = new MyClass*[K];
  for(int k=0; k<K; k++) {
    myVar[n][k] = new MyClass();

What do you would do inside the destructor?

Yeeesh. That makes my eyes hurt.

If you ever need to use ‘delete’ then you’re writing bad C++.

The whole point of C++ is that we’ve got RAII and containers to manage all this stuff for us. Put your objects in an OwnedArray/Array/HeapBlock/etc, and let the container handle the deletion. Avoid raw C arrays, and definitely never use nested raw arrays!

Thank you for the tip; that was I peace of code I got before using Juce, so I hoped to reuse without rewriting it… So now I think it’s the time to do it.