From a830f5600e65f5db240a80b6df866ec2cdc622c4 Mon Sep 17 00:00:00 2001 From: Kevin Ahrendt Date: Fri, 8 May 2026 12:32:14 +0000 Subject: [PATCH] proactively release the item in the ring buffer when it's fully consumed --- esphome/components/audio/audio_transfer_buffer.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/esphome/components/audio/audio_transfer_buffer.cpp b/esphome/components/audio/audio_transfer_buffer.cpp index 62aa161c2f..f91c89911b 100644 --- a/esphome/components/audio/audio_transfer_buffer.cpp +++ b/esphome/components/audio/audio_transfer_buffer.cpp @@ -242,8 +242,13 @@ void RingBufferAudioSource::consume(size_t bytes) { bytes = std::min(bytes, this->current_available_); this->current_data_ += bytes; this->current_available_ -= bytes; - // Release of the held item and promotion of queued data are deferred to fill() so callers see new - // data as a fresh return value rather than appearing silently after consume(). + // Promotion of queued data is deferred to fill() so callers see new data as a fresh return value + // rather than appearing silently after consume(). When the held item has nothing left depending + // on it (no exposed bytes and no queued region), release it now so the ring buffer can be + // reclaimed by writers even if fill() is never called again. + if (this->current_available_ == 0 && this->queued_length_ == 0) { + this->release_item_(); + } } bool RingBufferAudioSource::has_buffered_data() const {