diff --git a/common/notificationconsumer.cpp b/common/notificationconsumer.cpp index 4edfbfee4..edfe7f3be 100644 --- a/common/notificationconsumer.cpp +++ b/common/notificationconsumer.cpp @@ -2,6 +2,7 @@ #include #include +#include #include "redisapi.h" #define NOTIFICATION_SUBSCRIBE_TIMEOUT (1000) @@ -154,6 +155,27 @@ void swss::NotificationConsumer::pop(std::string &op, std::string &data, std::ve std::string msg = m_queue.front(); m_queue.pop(); + if (m_queue.empty()) + { + /*** + * If there is a burst of notifications that causes the queue to grow in size, + * memory allocated by the queue will not be released even after the all items + * have been popped. + * + * Force the memory to be released by destroying existing queue and creating a new one. + */ + SWSS_LOG_INFO("%s queue is empty, calling malloc_trim()", m_channel.c_str()); + int rv = malloc_trim(0); + if (rv == 1) + { + SWSS_LOG_DEBUG("Memory released successfully"); + } + else + { + SWSS_LOG_DEBUG("No memory released by malloc_trim"); + } + } + values.clear(); JSon::readJson(msg, values);