Skip to content

Commit df99856

Browse files
authored
Merge pull request #530 from Jarred-Sumner/bun
Add MI_SKIP_COLLECT_ON_EXIT flag
2 parents 2e3e978 + f4e2219 commit df99856

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
@@ -26,6 +26,7 @@ option(MI_DEBUG_UBSAN "Build with undefined-behavior sanitizer (needs clan
2626
option(MI_CHECK_FULL "Use full internal invariant checking in DEBUG mode (deprecated, use MI_DEBUG_FULL instead)" OFF)
2727
option(MI_INSTALL_TOPLEVEL "Install directly into $CMAKE_INSTALL_PREFIX instead of PREFIX/lib/mimalloc-version (deprecated)" OFF)
2828
option(MI_USE_LIBATOMIC "Explicitly link with -latomic (on older systems) (deprecated and detected automatically)" OFF)
29+
option(MI_SKIP_COLLECT_ON_EXIT, "Skip collecting memory on exit" OFF)
2930

3031
include(GNUInstallDirs)
3132
include("cmake/mimalloc-config-version.cmake")
@@ -117,6 +118,10 @@ if(MI_CHECK_FULL)
117118
set(MI_DEBUG_FULL "ON")
118119
endif()
119120

121+
if (MI_SKIP_COLLECT_ON_EXIT)
122+
list(APPEND mi_defines MI_SKIP_COLLECT_ON_EXIT=1)
123+
endif()
124+
120125
if(MI_DEBUG_FULL)
121126
message(STATUS "Set debug level to full internal invariant checking (MI_DEBUG_FULL=ON)")
122127
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
@@ -535,11 +535,13 @@ static void mi_process_done(void) {
535535
FlsFree(mi_fls_key); // call thread-done on all threads (except the main thread) to prevent dangling callback pointer if statically linked with a DLL; Issue #208
536536
#endif
537537

538-
#if (MI_DEBUG != 0) || !defined(MI_SHARED_LIB)
539-
// free all memory if possible on process exit. This is not needed for a stand-alone process
540-
// but should be done if mimalloc is statically linked into another shared library which
541-
// is repeatedly loaded/unloaded, see issue #281.
542-
mi_collect(true /* force */ );
538+
#ifndef MI_SKIP_COLLECT_ON_EXIT
539+
#if (MI_DEBUG != 0) || !defined(MI_SHARED_LIB)
540+
// free all memory if possible on process exit. This is not needed for a stand-alone process
541+
// but should be done if mimalloc is statically linked into another shared library which
542+
// is repeatedly loaded/unloaded, see issue #281.
543+
mi_collect(true /* force */ );
544+
#endif
543545
#endif
544546

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

0 commit comments

Comments
 (0)