From 9188bf8d81ac3a82e06433c7b37a6e3a91084661 Mon Sep 17 00:00:00 2001 From: "sfraser%netscape.com" Date: Sat, 14 Oct 2000 00:39:16 +0000 Subject: [PATCH] Fix for 53310; implement IsLowMemory() on Mac, and turn on the low memory detection thread. r=waterson, sr=scc. --- xpcom/base/nsMemoryImpl.cpp | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/xpcom/base/nsMemoryImpl.cpp b/xpcom/base/nsMemoryImpl.cpp index a4d76050f20..678731edb96 100644 --- a/xpcom/base/nsMemoryImpl.cpp +++ b/xpcom/base/nsMemoryImpl.cpp @@ -33,6 +33,9 @@ #if defined(XP_PC) && !defined(XP_OS2) #include #define NS_MEMORY_FLUSHER_THREAD +#elif defined(XP_MAC) +#include +#define NS_MEMORY_FLUSHER_THREAD #else // Need to implement the nsIMemory::IsLowMemory() predicate #undef NS_MEMORY_FLUSHER_THREAD @@ -337,6 +340,37 @@ nsMemoryImpl::IsLowMemory(PRBool *result) MEMORYSTATUS stat; GlobalMemoryStatus(&stat); *result = ((float)stat.dwAvailPageFile / stat.dwTotalPageFile) < 0.1; +#elif defined(XP_MAC) + + const long kReserveHeapFreeSpace = (256 * 1024); + const long kReserveHeapContigSpace = (128 * 1024); + + long totalSpace, contiguousSpace; + // this call measures how much memory would be available if the OS + // purged. Despite the name, it does not purge (that happens + // automatically when heap space is low). + ::PurgeSpace(&totalSpace, &contiguousSpace); + if (totalSpace < kReserveHeapFreeSpace || contiguousSpace < kReserveHeapContigSpace) + { + NS_WARNING("Found that heap mem is low"); + *result = PR_TRUE; + return NS_OK; + } + + // see how much temp mem is available (since our allocators allocate 1Mb chunks + // in temp mem. We don't use TempMaxMem() (to get contig space) here, because it + // compacts the application heap, so can be slow. + const long kReserveTempFreeSpace = (2 * 1024 * 1024); // 2Mb + long totalTempSpace = ::TempFreeMem(); + if (totalTempSpace < kReserveTempFreeSpace) + { + NS_WARNING("Found that temp mem is low"); + *result = PR_TRUE; + return NS_OK; + } + + *result = PR_FALSE; + #else *result = PR_FALSE; #endif