From 1de2b90ae50c0e132de19de8f896891415c02025 Mon Sep 17 00:00:00 2001 From: Nodir Temirkhodjaev Date: Thu, 14 Nov 2024 20:30:22 +0500 Subject: [PATCH] UI: LogManager::addFreeBuffer: Delete excessive buffers --- src/ui/log/logmanager.cpp | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/ui/log/logmanager.cpp b/src/ui/log/logmanager.cpp index 242addc9..42548fc2 100644 --- a/src/ui/log/logmanager.cpp +++ b/src/ui/log/logmanager.cpp @@ -95,15 +95,22 @@ void LogManager::cancelAsyncIo() LogBuffer *LogManager::getFreeBuffer() { - if (m_freeBuffers.isEmpty()) - return new LogBuffer(DriverCommon::bufferSize(), this); + if (!m_freeBuffers.isEmpty()) { + return m_freeBuffers.takeLast(); + } - return m_freeBuffers.takeLast(); + return new LogBuffer(DriverCommon::bufferSize(), this); } void LogManager::addFreeBuffer(LogBuffer *logBuffer) { - m_freeBuffers.append(logBuffer); + constexpr int maxBufferCount = 8; + if (m_freeBuffers.size() < maxBufferCount) { + m_freeBuffers.append(logBuffer); + return; + } + + delete logBuffer; } void LogManager::processLogBuffer(LogBuffer *logBuffer, bool success, quint32 errorCode)