Juce 7.0.2 - MacOS
I am still working (I’m sorry to say) on 10.14 Mojave with Xcode 10.3, so yes, it’s an older Xcode.
When I run the debugger, in the left side of Xcode there is the Debug Navigator, which shows CPU, Memory etc.
The Memory meter, I have noticed, is constantly going up little by little when my app is running, even if it’s just sitting there idling. If I leave it running overnight, it goes up by a huge amount!
After fooling around with some debugging, it seemed to be related to some LED style widgets I have that blink with the tempo, among other things. If I stop blinking them, it appears the memory usage stays level. I don’t see why…
So I built a simple test GUI App with a single blinking LED. Complete project here:
BlinkLedTest.zip (11.1 KB)
When I Run it from Xcode (Release Build), the Memory is at around 47.5 mb.
With it just sitting there and blinking, it slowly goes up continuously. An hour later it’s at 58 mb.
I let it run overnight. Now it’s now 225.4 mb!
This test Application inherits from private juce::HighResolutionTimer
. (I use this in my real app, so I used it here). I have a 1 ms clock running. So here, we have:
void initialise (const juce::String& commandLine) override
{
mainWindow.reset (new MainWindow (getApplicationName()));
HighResolutionTimer::startTimer (1); // 1 ms clock
}
long curTime = 0;
void hiResTimerCallback() override
{
curTime++;
if (curTime % 500 == 0) // twice per second
mainWindow->mainComponent->blinkLed();
}
So basically, we want to blink an LED twice a second (120 BPM).
The Led and MainComponent class:
class Led : public juce::Component,
public juce::AsyncUpdater
{
public:
Led() { }
void paint(juce::Graphics& g) override
{
if (isOn)
g.setColour(juce::Colours::yellow);
else
g.setColour(juce::Colours::black);
g.fillEllipse(getLocalBounds().toFloat());
}
void blink()
{
isOn = true;
triggerAsyncUpdate();
juce::Timer::callAfterDelay(200, [this]
{
isOn = false;
triggerAsyncUpdate();
});
}
void handleAsyncUpdate() override
{
repaint();
}
private:
bool isOn = false;
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (Led)
};
class MainComponent : public juce::Component
{
public:
MainComponent();
~MainComponent() override;
void paint (juce::Graphics&) override;
void resized() override;
void blinkLed()
{
led.blink();
}
private:
Led led;
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (MainComponent)
};
So, when we blink() the Led, it sets a variable isOn and triggers an AsyncUpdate which calls repaint(). It also uses Timer::callAfterDelay() to schedule the Led to turn off 200 ms later, with another AsyncUpdate and repaint().
Pretty straightforward (it seems). This isn’t exactly what I’m doing in my real app, but it doesn’t matter - because this simple test project does the same thing!
Am I reading this wrong and it’s nothing to worry about, or is this an indication that something is wrong within JUCE?
I will admit I’m clueless about using Instruments, and when I run it, I don’t know how to interpret the data…