Browse Source

Fix mem leaks on close; Always print in juce LeakObjectDectetor

tags/1.9.4
falkTX 11 years ago
parent
commit
24f472ac1a
3 changed files with 39 additions and 20 deletions
  1. +17
    -8
      source/backend/engine/CarlaEngineJuce.cpp
  2. +17
    -8
      source/backend/engine/CarlaEngineRtAudio.cpp
  3. +5
    -4
      source/modules/juce_core/memory/juce_LeakedObjectDetector.h

+ 17
- 8
source/backend/engine/CarlaEngineJuce.cpp View File

@@ -47,6 +47,23 @@ static void initJuceDevices()
manager.createAudioDeviceTypes(gJuceDeviceTypes); manager.createAudioDeviceTypes(gJuceDeviceTypes);
} }


// -------------------------------------------------------------------------------------------------------------------
// Cleanup

static struct JuceCleanup {
JuceCleanup() {}
~JuceCleanup()
{
if (gRetNames != nullptr)
{
delete[] gRetNames;
gRetNames = nullptr;
}

gJuceDeviceTypes.clear(true);
}
} sJuceCleanup;

// ------------------------------------------------------------------------------------------------------------------- // -------------------------------------------------------------------------------------------------------------------
// Juce Engine // Juce Engine


@@ -68,14 +85,6 @@ public:
~CarlaEngineJuce() override ~CarlaEngineJuce() override
{ {
carla_debug("CarlaEngineJuce::~CarlaEngineJuce()"); carla_debug("CarlaEngineJuce::~CarlaEngineJuce()");

if (gRetNames != nullptr)
{
delete[] gRetNames;
gRetNames = nullptr;
}

gJuceDeviceTypes.clear(true);
} }


// ------------------------------------- // -------------------------------------


+ 17
- 8
source/backend/engine/CarlaEngineRtAudio.cpp View File

@@ -135,6 +135,23 @@ static RtMidi::Api getMatchedAudioMidiAPi(const RtAudio::Api rtApi)
return RtMidi::UNSPECIFIED; return RtMidi::UNSPECIFIED;
} }


// -------------------------------------------------------------------------------------------------------------------
// Cleanup

static struct RtAudioCleanup {
RtAudioCleanup() {}
~RtAudioCleanup()
{
if (gRetNames != nullptr)
{
delete[] gRetNames;
gRetNames = nullptr;
}

gRtAudioApis.clear();
}
} sRtAudioCleanup;

// ------------------------------------------------------------------------------------------------------------------- // -------------------------------------------------------------------------------------------------------------------
// RtAudio Engine // RtAudio Engine


@@ -165,14 +182,6 @@ public:


fUsedMidiIns.clear(); fUsedMidiIns.clear();
fUsedMidiOuts.clear(); fUsedMidiOuts.clear();

if (gRetNames != nullptr)
{
delete[] gRetNames;
gRetNames = nullptr;
}

gRtAudioApis.clear();
} }


// ------------------------------------- // -------------------------------------


+ 5
- 4
source/modules/juce_core/memory/juce_LeakedObjectDetector.h View File

@@ -29,6 +29,7 @@
#ifndef JUCE_LEAKEDOBJECTDETECTOR_H_INCLUDED #ifndef JUCE_LEAKEDOBJECTDETECTOR_H_INCLUDED
#define JUCE_LEAKEDOBJECTDETECTOR_H_INCLUDED #define JUCE_LEAKEDOBJECTDETECTOR_H_INCLUDED
#define DBG2(dbgtext) { juce::String str; str << dbgtext; std::cout << str.toRawUTF8() << std::endl; }
//============================================================================== //==============================================================================
/** /**
@@ -55,7 +56,7 @@ public:
{ {
if (--(getCounter().numObjects) < 0) if (--(getCounter().numObjects) < 0)
{ {
DBG ("*** Dangling pointer deletion! Class: " << getLeakedObjectClassName());
DBG2 ("*** Dangling pointer deletion! Class: " << getLeakedObjectClassName());
/** If you hit this, then you've managed to delete more instances of this class than you've /** If you hit this, then you've managed to delete more instances of this class than you've
created.. That indicates that you're deleting some dangling pointers. created.. That indicates that you're deleting some dangling pointers.
@@ -68,7 +69,7 @@ public:
your object management. Tut, tut. Always, always use ScopedPointers, OwnedArrays, your object management. Tut, tut. Always, always use ScopedPointers, OwnedArrays,
ReferenceCountedObjects, etc, and avoid the 'delete' operator at all costs! ReferenceCountedObjects, etc, and avoid the 'delete' operator at all costs!
*/ */
jassertfalse;
//jassertfalse;
} }
} }
@@ -83,7 +84,7 @@ private:
{ {
if (numObjects.value > 0) if (numObjects.value > 0)
{ {
DBG ("*** Leaked objects detected: " << numObjects.value << " instance(s) of class " << getLeakedObjectClassName());
DBG2 ("*** Leaked objects detected: " << numObjects.value << " instance(s) of class " << getLeakedObjectClassName());
/** If you hit this, then you've leaked one or more objects of the type specified by /** If you hit this, then you've leaked one or more objects of the type specified by
the 'OwnerClass' template parameter - the name should have been printed by the line above. the 'OwnerClass' template parameter - the name should have been printed by the line above.
@@ -92,7 +93,7 @@ private:
your object management. Tut, tut. Always, always use ScopedPointers, OwnedArrays, your object management. Tut, tut. Always, always use ScopedPointers, OwnedArrays,
ReferenceCountedObjects, etc, and avoid the 'delete' operator at all costs! ReferenceCountedObjects, etc, and avoid the 'delete' operator at all costs!
*/ */
jassertfalse;
//jassertfalse;
} }
} }


Loading…
Cancel
Save