I set up visual leak detector with my code, and suddenly got loads of leaks, when Juce’s leak detector reported none.
Since all leaks from VLD seem to be from the same static function (), and I found some information on the internet on it reporting false positives sometimes, I though’t I’d check here to make sure that that’s the case.
I made a test program, with the code below, in the MainComponent constructor of my program, which is reported as leaking by VLD:
Value test_Value;
test_Value = 0.0;
String test_label;
test_label = test_Value.toString();
Where that last .toString() call is reported as responsible for 5 leaks.
Should I just ignore this as a false positive, or is there something wrong in my code above? I’m relatively new to C++, but I don’t see why that code should be leaking really
Oh, and I’m using the latest Juce modules, as of yesterday.
Your code creates a string and passes it to something called test_label, but you haven’t explained what that variable is. Is it a static string? If so then it’s probably still hanging around when VLD runs, and looks like a leak.
Both variables (test_Value and test_label) are declared just above the line reported as leaking. I didn’t tag the whole thing as code, here it is again for clarity:
Value test_Value;
test_Value = 0.0;
String test_label;
test_label = test_Value.toString();
And the line detected as leaking is only the last one.
So I imagine that as soon as the constructor in which those lines of code live ends, they go out of scope and are deleted, since they are allocated to the stack. Unless I’ve gotten something very wrong of course!
Oh sorry, I mis-read it. Well, there’s certainly nothing wrong with that code… I don’t know anything about how VLD works, but I’d say it’s a probably a false alarm.
Ah, maybe it’s just the variant’s internal static classes that it thinks are leaking. There are a few singleton-style objects used in there, but definitely not a real leak.
No, VLD does actually work with static as with anything else.
VLD is a static library that’s linked with a special pragma flag telling to be started first (and ended last).
However, some static objects are never destructed when you leave your application in Juce. They’ll be cleaned by the C library. VLD can’t detect the cleaning/destruction, and report a leaks.
VLD is not completely wrong here, since a static object that’s always increasing in size (and that will be cleaned at very very last step) is not a good code anyway.
Don’t use a static ValueTree for example.
I’m using VLD on Windows and valgrind on linux, and both are reporting the exact same leaks (but as Jules said, they are not “growing”, so it’s not worth considering as a “leak”).
(Off topic, did you know that there is no “free” in busybox code at all ? This is because when a process exits, the kernel cleans the memory faster/better than you could do, and adding “free” everywhere just increase the size of the binary, which for a project like busybox, in unacceptable).