Commit 1616e8b8 authored by Aleix Pol Gonzalez's avatar Aleix Pol Gonzalez 🐧
Browse files

safety

Try not to keep objects that might get destroyed in memory unless necessary

CCBUG: 412632
parent fd5dcfa7
......@@ -304,7 +304,7 @@ AggregatedResultsStream::AggregatedResultsStream(const QSet<ResultsStream*>& str
for (auto stream: streams) {
connect(stream, &ResultsStream::resourcesFound, this, &AggregatedResultsStream::addResults);
connect(stream, &QObject::destroyed, this, &AggregatedResultsStream::destruction);
connect(stream, &QObject::destroyed, this, &AggregatedResultsStream::streamDestruction);
connect(this, &ResultsStream::fetchMore, stream, &ResultsStream::fetchMore);
m_streams << stream;
}
......@@ -318,9 +318,7 @@ AggregatedResultsStream::~AggregatedResultsStream() = default;
void AggregatedResultsStream::addResults(const QVector<AbstractResource *>& res)
{
for(auto r : res)
connect(r, &QObject::destroyed, this, [this, r](){
m_results.removeAll(r);
});
connect(r, &QObject::destroyed, this, &AggregatedResultsStream::resourceDestruction);
m_results += res;
......@@ -337,7 +335,12 @@ void AggregatedResultsStream::emitResults()
m_delayedEmission.stop();
}
void AggregatedResultsStream::destruction(QObject* obj)
void AggregatedResultsStream::resourceDestruction(QObject* obj)
{
m_results.removeAll(qobject_cast<AbstractResource*>(obj));
}
void AggregatedResultsStream::streamDestruction(QObject* obj)
{
m_streams.remove(obj);
clear();
......
......@@ -43,7 +43,8 @@ Q_SIGNALS:
private:
void addResults(const QVector<AbstractResource*>& res);
void emitResults();
void destruction(QObject* obj);
void streamDestruction(QObject* obj);
void resourceDestruction(QObject* obj);
void clear();
QSet<QObject*> m_streams;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment