From 155b7b698ecab50ecf47349d3c9081c82c0038df Mon Sep 17 00:00:00 2001 From: Svyatoslav Scherbina Date: Wed, 4 Jul 2018 10:41:37 +0300 Subject: [PATCH] Fix minor bug in memory management Properly handle the case when the program finishes with empty 'toFree' buffer but non-empty deallocation queue. --- backend.native/tests/build.gradle | 4 ++++ backend.native/tests/runtime/memory/only_gc.kt | 4 ++++ runtime/src/main/cpp/Memory.cpp | 2 ++ 3 files changed, 10 insertions(+) create mode 100644 backend.native/tests/runtime/memory/only_gc.kt diff --git a/backend.native/tests/build.gradle b/backend.native/tests/build.gradle index cfa46aeeb2f..a9a6b5d7de2 100644 --- a/backend.native/tests/build.gradle +++ b/backend.native/tests/build.gradle @@ -2205,6 +2205,10 @@ task memory_weak1(type: RunKonanTest) { source = "runtime/memory/weak1.kt" } +task memory_only_gc(type: RunStandaloneKonanTest) { + source = "runtime/memory/only_gc.kt" +} + task mpp1(type: RunStandaloneKonanTest) { source = "codegen/mpp/mpp1.kt" flags = ['-tr', '-Xmulti-platform'] diff --git a/backend.native/tests/runtime/memory/only_gc.kt b/backend.native/tests/runtime/memory/only_gc.kt new file mode 100644 index 00000000000..b2da7c12861 --- /dev/null +++ b/backend.native/tests/runtime/memory/only_gc.kt @@ -0,0 +1,4 @@ +fun main(args: Array) { + konan.internal.GC.collect() +} + diff --git a/runtime/src/main/cpp/Memory.cpp b/runtime/src/main/cpp/Memory.cpp index de002dfa648..ed940f2c49f 100644 --- a/runtime/src/main/cpp/Memory.cpp +++ b/runtime/src/main/cpp/Memory.cpp @@ -1358,6 +1358,8 @@ void GarbageCollect() { state->gcInProgress = true; + processFinalizerQueue(state); + while (state->toFree->size() > 0) { CollectCycles(state); processFinalizerQueue(state);