diff --git a/Telegram/SourceFiles/history/history.cpp b/Telegram/SourceFiles/history/history.cpp index b1dd74e540..957b71b215 100644 --- a/Telegram/SourceFiles/history/history.cpp +++ b/Telegram/SourceFiles/history/history.cpp @@ -3060,14 +3060,15 @@ void History::clear(ClearType type) { _loadedAtTop = _loadedAtBottom = false; } else { // Leave the 'sending' messages in local messages. - for (auto i = begin(_localMessages); i != end(_localMessages);) { - const auto item = *i; + auto local = base::flat_set>(); + for (const auto item : _localMessages) { if (!item->isSending()) { - i = _localMessages.erase(i); - } else { - ++i; + local.emplace(item); } } + for (const auto item : local) { + item->destroy(); + } _notifications.clear(); owner().notifyHistoryCleared(this); if (unreadCountKnown()) {