diff --git a/tt_metal/impl/allocator/algorithms/free_list.cpp b/tt_metal/impl/allocator/algorithms/free_list.cpp index f508af97548..07253ca2761 100644 --- a/tt_metal/impl/allocator/algorithms/free_list.cpp +++ b/tt_metal/impl/allocator/algorithms/free_list.cpp @@ -20,7 +20,21 @@ FreeList::FreeList(DeviceAddr max_size_bytes, DeviceAddr offset_bytes, DeviceAdd this->init(); } +FreeList::~FreeList() { + this->clear(); +} + void FreeList::init() { + boost::local_shared_ptr curr_block = this->block_head_; + while (curr_block != nullptr) { + auto next_block = curr_block->next_block; + curr_block->prev_block = nullptr; + curr_block->next_block = nullptr; + curr_block->prev_free = nullptr; + curr_block->next_free = nullptr; + curr_block = next_block; + } + this->shrink_size_ = 0; auto block = boost::make_local_shared(0, this->max_size_bytes_); this->block_head_ = block; diff --git a/tt_metal/impl/allocator/algorithms/free_list.hpp b/tt_metal/impl/allocator/algorithms/free_list.hpp index f0756dd7803..96f18513fe8 100644 --- a/tt_metal/impl/allocator/algorithms/free_list.hpp +++ b/tt_metal/impl/allocator/algorithms/free_list.hpp @@ -19,6 +19,7 @@ class FreeList : public Algorithm { }; FreeList(DeviceAddr max_size_bytes, DeviceAddr offset_bytes, DeviceAddr min_allocation_size, DeviceAddr alignment, SearchPolicy search_policy); + ~FreeList(); void init(); std::vector> available_addresses(DeviceAddr size_bytes) const;