I created an audio DJ that also uses tables to add songs to it etc but when I close it I get a lot of leaked errors.
*** Leaked objects detected: 13 instance(s) of class JuceIStream
JUCE Assertion failure in juce_LeakedObjectDetector.h:92
*** Leaked objects detected: 13 instance(s) of class WMAudioReader
JUCE Assertion failure in juce_LeakedObjectDetector.h:92
*** Leaked objects detected: 13 instance(s) of class DynamicLibrary
JUCE Assertion failure in juce_LeakedObjectDetector.h:92
*** Leaked objects detected: 13 instance(s) of class AudioFormatReader
JUCE Assertion failure in juce_LeakedObjectDetector.h:92
*** Leaked objects detected: 13 instance(s) of class FileInputStream
JUCE Assertion failure in juce_LeakedObjectDetector.h:92
*** Leaked objects detected: 13 instance(s) of class MemoryBlock
JUCE Assertion failure in juce_LeakedObjectDetector.h:92
*** Leaked objects detected: 13 instance(s) of class InputStream
JUCE Assertion failure in juce_LeakedObjectDetector.h:92
*** Leaked objects detected: 13 instance(s) of class StringPairArray
JUCE Assertion failure in juce_LeakedObjectDetector.h:92
*** Leaked objects detected: 26 instance(s) of class StringArray
JUCE Assertion failure in juce_LeakedObjectDetector.h:92
You are probably using raw pointers or global/static variables for your objects. Then you will easily get leaks of multiple kinds of Juce objects. Itâs impossible to say without seeing the whole code why exactly you are getting the leaks.
Pointers are just pointers, but they require that you manually manage their lifetimes. Ie. You have to remember to delete the allocated memory when you are done with it.
BUT, the good news is you can use some cool objects from the standard library to help automate that. The most common is âstd::unique_pointerâ. This holds your raw pointer, and when the âunique _ptrâ object goes out of scope, it automatically deletes the allocated memory. In modern c++ you should default to using a âunique_ptrâ, consider other pointer containers for some specific use cases, and only use raw pointers when required (for reasons, )
You shouldnât use regular global variables for Juce objects, as the leak detection mechanism in Juce doesnât really work with those. Thereâs a way to make global variables that is compatible with the Juce leak detection, but you should consider not using the globals to begin with. Thereâs rarely any good reason to use global variables. (That those can make some things easier for the programmer is not a good reason.)
Global variables meaning itâs global to every function in that class right? Iâll have to find a way to cut down on most of them but I do need global variables for most
Variables in classes are not âglobalâ, they are âmember variablesâ. Unless they are âstaticâ members. Global variable is something declared outside a class context, and which could be accessed all over the code.