diff OrthancServer/Sources/ServerContext.cpp @ 5159:f5907aecbaed

conditional usage of malloc_trim
author Alain Mazy <am@osimis.io>
date Thu, 02 Feb 2023 11:28:35 +0100
parents c81f363d3aa3
children 9f16979b6124
line wrap: on
line diff
--- a/OrthancServer/Sources/ServerContext.cpp	Thu Feb 02 10:33:15 2023 +0100
+++ b/OrthancServer/Sources/ServerContext.cpp	Thu Feb 02 11:28:35 2023 +0100
@@ -107,14 +107,16 @@
   void ServerContext::HousekeeperThread(ServerContext* that,
                                         unsigned int sleepDelay)
   {
+    // note, right now, this thread is started only if malloc_trim is defined
     while (!that->done_)
     {
       boost::this_thread::sleep(boost::posix_time::milliseconds(sleepDelay));
       
       // If possible, gives memory back to the system 
       // (see OrthancServer/Resources/ImplementationNotes/memory_consumption.txt)
-
-      malloc_trim(256*1024);
+#if HAVE_MALLOC_TRIM == 1
+      malloc_trim(128*1024);
+#endif
     }
   }
   
@@ -430,8 +432,11 @@
 
       listeners_.push_back(ServerListener(luaListener_, "Lua"));
       changeThread_ = boost::thread(ChangeThread, this, (unitTesting ? 20 : 100));
+#if HAVE_MALLOC_TRIM == 1
       housekeeperThread_ = boost::thread(HousekeeperThread, this, 100);
-
+#else
+      LOG(INFO) << "Your platform does not support malloc_trim(), not starting the housekeeper thread";
+#endif
       dynamic_cast<DcmtkTranscoder&>(*dcmtkTranscoder_).SetLossyQuality(lossyQuality);
     }
     catch (OrthancException&)