From 2b55dabe39046cf732e1fef14b4a861bcd5f8c0d Mon Sep 17 00:00:00 2001 From: fasiondog Date: Sat, 1 Jun 2024 14:41:32 +0800 Subject: [PATCH] =?UTF-8?q?=E9=9D=9E=E6=B3=84=E6=BC=8F=E6=A3=80=E6=B5=8B?= =?UTF-8?q?=E6=A8=A1=E5=BC=8F=E4=B8=8B=E7=9B=B4=E6=8E=A5=E9=80=80=E5=87=BA?= =?UTF-8?q?=EF=BC=8C=E8=AE=A9=E7=B3=BB=E7=BB=9F=E9=87=8A=E6=94=BE=E8=B5=84?= =?UTF-8?q?=E6=BA=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config.h.in | 3 +++ hikyuu_cpp/hikyuu/GlobalInitializer.cpp | 8 ++++++-- xmake.lua | 1 + 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/config.h.in b/config.h.in index a4ec7bef..798234db 100644 --- a/config.h.in +++ b/config.h.in @@ -34,6 +34,9 @@ // 启用MSVC内存泄漏检查 #define ENABLE_MSVC_LEAK_DETECT ${ENABLE_MSVC_LEAK_DETECT} +// 启用内存泄漏检测,用于 linux 系统 +#define HKU_ENABLE_LEAK_DETECT ${HKU_ENABLE_LEAK_DETECT} + // 启用发送用户使用信息 #define HKU_ENABLE_SEND_FEEDBACK ${HKU_ENABLE_SEND_FEEDBACK} diff --git a/hikyuu_cpp/hikyuu/GlobalInitializer.cpp b/hikyuu_cpp/hikyuu/GlobalInitializer.cpp index f2c12c22..08420018 100644 --- a/hikyuu_cpp/hikyuu/GlobalInitializer.cpp +++ b/hikyuu_cpp/hikyuu/GlobalInitializer.cpp @@ -84,6 +84,12 @@ void GlobalInitializer::clean() { getLatestVersion(), getLatestVersion()); } +#if !HKU_ENABLE_LEAK_DETECT && not defined(MSVC_LEAKER_DETECT) + // 未启用内存泄漏检测时,直接退出,让系统自行释放全部资源 + fmt::print("Quit Hikyuu system!\n\n"); + return; +#endif + releaseGlobalTaskGroup(); releaseScheduler(); releaseGlobalSpotAgent(); @@ -92,8 +98,6 @@ void GlobalInitializer::clean() { StockManager::quit(); DataDriverFactory::release(); - nng_closeall(); - #if HKU_ENABLE_HDF5_KDATA H5close(); #endif diff --git a/xmake.lua b/xmake.lua index c88e2d4d..29bbc0d2 100644 --- a/xmake.lua +++ b/xmake.lua @@ -148,6 +148,7 @@ set_configvar("SUPPORT_TEXT_ARCHIVE", 0) set_configvar("SUPPORT_XML_ARCHIVE", 1) set_configvar("SUPPORT_BINARY_ARCHIVE", 1) set_configvar("ENABLE_MSVC_LEAK_DETECT", 0) +set_configvar("HKU_ENABLE_LEAK_DETECT", get_config("leak_check") and 1 or 0) set_configvar("HKU_ENABLE_SEND_FEEDBACK", get_config("feedback") and 1 or 0) set_configvar("HKU_ENABLE_HDF5_KDATA", get_config("hdf5") and 1 or 0)