diff --git a/src/arena.c b/src/arena.c index 5867b5c5..4910d8ca 100644 --- a/src/arena.c +++ b/src/arena.c @@ -712,7 +712,7 @@ static void mi_arenas_unsafe_destroy(void) { // Purge the arenas; if `force_purge` is true, amenable parts are purged even if not yet expired void _mi_arena_collect(bool force_purge, mi_stats_t* stats) { - mi_arenas_try_purge(force_purge, true /* visit all */, stats); + mi_arenas_try_purge(force_purge, force_purge /* visit all? */, stats); } // destroy owned arenas; this is unsafe and should only be done using `mi_option_destroy_on_exit` diff --git a/src/heap.c b/src/heap.c index ef989eb0..214d92e9 100644 --- a/src/heap.c +++ b/src/heap.c @@ -120,7 +120,7 @@ static void mi_heap_collect_ex(mi_heap_t* heap, mi_collect_t collect) { if (heap==NULL || !mi_heap_is_initialized(heap)) return; - const bool force = collect >= MI_FORCE; + const bool force = (collect >= MI_FORCE); _mi_deferred_free(heap, force); // note: never reclaim on collect but leave it to threads that need storage to reclaim @@ -163,11 +163,13 @@ static void mi_heap_collect_ex(mi_heap_t* heap, mi_collect_t collect) _mi_segment_thread_collect(&heap->tld->segments); } - // collect regions on program-exit (or shared library unload) + // if forced, collect thread data cache on program-exit (or shared library unload) if (force && _mi_is_main_thread() && mi_heap_is_backing(heap)) { _mi_thread_data_collect(); // collect thread data cache - _mi_arena_collect(true /* force purge */, &heap->tld->stats); } + + // collect arenas + _mi_arena_collect(force /* force purge? */, &heap->tld->stats); } void _mi_heap_collect_abandon(mi_heap_t* heap) {