diff --git a/include/zasm/core/objectpool.hpp b/include/zasm/core/objectpool.hpp index cc2e33a..bacada6 100644 --- a/include/zasm/core/objectpool.hpp +++ b/include/zasm/core/objectpool.hpp @@ -71,8 +71,12 @@ namespace zasm void reset() { - _blocks.clear(); - _blocks.push_back(std::make_unique()); + // Shrink to single block. + _blocks.resize(1); + + // Reset slot to zero. + _blocks[0]->slot = 0; + _freeItem = nullptr; } diff --git a/src/zasm/src/program/program.cpp b/src/zasm/src/program/program.cpp index 67db6e5..319d312 100644 --- a/src/zasm/src/program/program.cpp +++ b/src/zasm/src/program/program.cpp @@ -331,8 +331,12 @@ namespace zasm notifyObservers(&Observer::onNodeDestroy, state.observer, node); - // Ensure node is not in the list anymore. - detach_(node, state); + // If this is called from clear or from destructor we can skip unlinking. + if (!quickDestroy) + { + // Ensure node is not in the list anymore. + detach_(node, state); + } // Release. auto* nodeToDestroy = detail::toInternal(node); @@ -377,6 +381,11 @@ namespace zasm node = next; } + _state->head = nullptr; + _state->tail = nullptr; + _state->nextNodeId = {}; + _state->nodeCount = 0; + _state->nodeMap.clear(); _state->sections.clear(); _state->labels.clear();