From 41727f1224d48ca9a1cef4750773f575e14f763c Mon Sep 17 00:00:00 2001 From: Stepan Usatiuk Date: Wed, 3 Jan 2024 14:14:29 +0100 Subject: [PATCH] cleanup memory on exit --- src/vm/src/MemoryContext.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/vm/src/MemoryContext.cpp b/src/vm/src/MemoryContext.cpp index 01753a7..139887e 100644 --- a/src/vm/src/MemoryContext.cpp +++ b/src/vm/src/MemoryContext.cpp @@ -20,6 +20,15 @@ MemoryContext::MemoryContext() { } MemoryContext::~MemoryContext() { + // Three times because the first one might not start it as it's been running already + // second one as it might skip something because something has been dirtied + // and the third one everything should be cleaned + request_gc_and_wait(); + request_gc_and_wait(); + request_gc_and_wait(); + + assert(cell_count() == 0); + MemoryContext *expected = this; if (!CURRENT_MC.compare_exchange_strong(expected, nullptr)) { std::cerr << "Global MC pointer was overwritten!" << std::endl;