ok, here’s the test code for you juce devs. @dave96 @jules @fabian @ed95 no leak messages, but the memory usage keeps increasing. This should be a fun bug to solve!
Make a generic GUI project, and put this in MainComponent.h:
class MainContentComponent : public Component, public Timer
{
public:
//==============================================================================
MainContentComponent();
~MainContentComponent() { stopTimer(); }
void paint (Graphics&) override;
void resized() override {}
void timerCallback() override;
void addJob(std::function<bool()> lambda);
private:
ThreadPool pool;
//==============================================================================
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (MainContentComponent)
};
put this in MainComponent.cpp:
MainContentComponent::MainContentComponent()
{
setSize (600, 400);
startTimer(1000 * 3);
}
void MainContentComponent::paint (Graphics& g)
{
g.fillAll (Colour (0xff001F36));
g.setFont (Font (16.0f));
g.setColour (Colours::white);
g.drawText ("Hello World!", getLocalBounds(), Justification::centred, true);
}
void MainContentComponent::timerCallback()
{
auto a = []()
{
int statusCode = 0;
juce::URL serverRequestURL = juce::URL("https://www.google.com/search?q=what+is+the+area+of+a+square&rlz=1C5CHFA_enUS699US702&oq=what+is+the+area+of+a+square&aqs=chrome.0.0l6.9325j0j8&sourceid=chrome&ie=UTF-8");
ScopedPointer<InputStream> stream( serverRequestURL.createInputStream(true,
nullptr,
nullptr,
juce::String(),
20000,
//-1, //infinite timeout
nullptr,
&statusCode )
);
juce::String reply = "FailedToConnect";
bool result = false;
if( stream != nullptr ) {
reply = stream->readEntireStreamAsString();
result = true;
}
return result;
};
addJob(a);
}
void MainContentComponent::addJob(std::function<bool ()> lambda)
{
struct LambdaJobWrapper : public juce::ThreadPoolJob
{
LambdaJobWrapper(std::function<bool()> j) : juce::ThreadPoolJob("lambda"), job(j) {}
juce::ThreadPoolJob::JobStatus runJob() override
{
if( shouldExit() )
return juce::ThreadPoolJob::JobStatus::jobNeedsRunningAgain;
if( job() )
{
DBG( "LambdaJobWrapper::runJob() result: OK" );
}
else
{
DBG( "LambdaJobWrapper::runJob() result: FAIL" );
}
return juce::ThreadPoolJob::JobStatus::jobHasFinished;
}
std::function<bool()> job;
};
pool.addJob(new LambdaJobWrapper(lambda), true);
}
just want to add that I’m using Juce 4.3.1 here