Skip to content

Commit d2e727f

Browse files
committed
Add MI_SKIP_COLLECT_ON_EXIT flag
1 parent 076f815 commit d2e727f

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ option(MI_DEBUG_TSAN "Build with thread sanitizer (needs clang)" OFF)
2323
option(MI_DEBUG_UBSAN "Build with undefined-behavior sanitizer (needs clang++)" OFF)
2424
option(MI_CHECK_FULL "Use full internal invariant checking in DEBUG mode (deprecated, use MI_DEBUG_FULL instead)" OFF)
2525
option(MI_INSTALL_TOPLEVEL "Install directly into $CMAKE_INSTALL_PREFIX instead of PREFIX/lib/mimalloc-version" OFF)
26+
option(MI_SKIP_COLLECT_ON_EXIT, "Skip collecting memory on exit" OFF)
2627

2728
include("cmake/mimalloc-config-version.cmake")
2829

@@ -102,6 +103,10 @@ if(MI_CHECK_FULL)
102103
set(MI_DEBUG_FULL "ON")
103104
endif()
104105

106+
if (MI_SKIP_COLLECT_ON_EXIT)
107+
list(APPEND mi_defines MI_SKIP_COLLECT_ON_EXIT=1)
108+
endif()
109+
105110
if(MI_DEBUG_FULL)
106111
message(STATUS "Set debug level to full internal invariant checking (MI_DEBUG_FULL=ON)")
107112
list(APPEND mi_defines MI_DEBUG=3) # full invariant checking

src/init.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -516,11 +516,13 @@ static void mi_process_done(void) {
516516
FlsFree(mi_fls_key); // call thread-done on all threads to prevent dangling callback pointer if statically linked with a DLL; Issue #208
517517
#endif
518518

519-
#if (MI_DEBUG != 0) || !defined(MI_SHARED_LIB)
520-
// free all memory if possible on process exit. This is not needed for a stand-alone process
521-
// but should be done if mimalloc is statically linked into another shared library which
522-
// is repeatedly loaded/unloaded, see issue #281.
523-
mi_collect(true /* force */ );
519+
#ifndef MI_SKIP_COLLECT_ON_EXIT
520+
#if (MI_DEBUG != 0) || !defined(MI_SHARED_LIB)
521+
// free all memory if possible on process exit. This is not needed for a stand-alone process
522+
// but should be done if mimalloc is statically linked into another shared library which
523+
// is repeatedly loaded/unloaded, see issue #281.
524+
mi_collect(true /* force */ );
525+
#endif
524526
#endif
525527

526528
if (mi_option_is_enabled(mi_option_show_stats) || mi_option_is_enabled(mi_option_verbose)) {

0 commit comments

Comments
 (0)