Leaked Objects help


#1

I just updated to the latest tip. My application builds and runs on windows without problems but on Linux I get a load of “*** Leaked objects detected:…” followed by loads of assertion failures. Should I not be getting the same problems with Windows? Secondly does anyone have any advice on how to catch the offending objects? For instance one error reads like this:

*** Leaked objects detected: 34 instance(s) of class GlyphInfo
JUCE Assertion failure in …/…/JuceLibraryCode/…/…/juceTip/juce/amalgamation/…/src/containers/…/core/…/memory/juce_LeakedObjectDetector.h, line 95

I don’t use this class in my app but I guess it’s related to another class which I do use. Is there any way I can get the names of the leaked objects or get any further information to help me fix the problems?

Thanks.


#2

The leak detector’s only a quick-and-dirty method to tell you that something’s wrong, but at least one of the classes that it lists must have been leaked by your code. E.g. glyphinfo is used in CustomTypeface, so maybe you leaked one of those?


#3

I’m under no illusions that my code is water tight. I’m pretty sure there are objects being leaked. Would you say that best practice here would be to find the classes that I do use and start by making sure they are not leaking. Oh god. I wish the leak detector was here when I started my project. I’ve learned more about C++ from using Juce then I have from any book. Looks like I’m about ready to start a new chapter…


#4

It’s not difficult to be leak-free - the basic rule is to never, ever use the delete operator.

That way, you’re forced to use stack objects, embedded members, ScopedPointer, etc to manage your objects - and if you do that, it’s unlikely that you’ll leak anything.


#5

Thanks, I’ll give that a go. I do use the delete operator a few times but not so often with Juce classes. I’ll tidy things up and see where I get.