From 283710af899ce5b38239d7a331a257f1d244f757 Mon Sep 17 00:00:00 2001 From: "sfraser%netscape.com" Date: Fri, 22 Sep 2000 00:17:07 +0000 Subject: [PATCH] Fixing Mac out of memory blocker (dupped to bug 20743); make the low memory buffer purgeable again after reallocating it, and tweak the heap space numbers for GWorld allocations. r=pchen, sr=scc git-svn-id: svn://10.0.0.236/trunk@79787 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/gfx/src/mac/nsDrawingSurfaceMac.cpp | 5 +++-- mozilla/gfx/src/mac/nsImageMac.cpp | 6 +++--- mozilla/widget/src/mac/nsToolkit.cpp | 13 +++++++++---- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/mozilla/gfx/src/mac/nsDrawingSurfaceMac.cpp b/mozilla/gfx/src/mac/nsDrawingSurfaceMac.cpp index 94b4fcef359..eb239c23ccf 100644 --- a/mozilla/gfx/src/mac/nsDrawingSurfaceMac.cpp +++ b/mozilla/gfx/src/mac/nsDrawingSurfaceMac.cpp @@ -244,8 +244,6 @@ NS_IMETHODIMP nsDrawingSurfaceMac :: Init(nsIWidget *aTheWidget) * @update 3/02/99 dwc * @return error status */ -#define kReserveHeapFreeSpace (256 * 1024) -#define kReserverHeapContigSpace (64 * 1024) NS_IMETHODIMP nsDrawingSurfaceMac :: Init(PRUint32 aDepth,PRUint32 aWidth,PRUint32 aHeight, PRUint32 aFlags) { @@ -272,6 +270,9 @@ NS_IMETHODIMP nsDrawingSurfaceMac :: Init(PRUint32 aDepth,PRUint32 aWidth,PRUint // Quick and dirty check to make sure there is some memory available. // GWorld allocations in temp mem can still fail if the heap is totally // full, because some stuff is allocated in the heap + const long kReserveHeapFreeSpace = (256 * 1024); + const long kReserverHeapContigSpace = (128 * 1024); + QDErr err = noErr; long totalSpace, contiguousSpace; diff --git a/mozilla/gfx/src/mac/nsImageMac.cpp b/mozilla/gfx/src/mac/nsImageMac.cpp index 2bd4a0d8eb5..334130599da 100644 --- a/mozilla/gfx/src/mac/nsImageMac.cpp +++ b/mozilla/gfx/src/mac/nsImageMac.cpp @@ -486,9 +486,6 @@ void nsImageMac::ClearGWorld(GWorldPtr theGWorld) /** ----------------------------------------------------------------- * Allocate a GWorld, trying first in the heap, and then in temp mem. */ -#define kReserveHeapFreeSpace (256 * 1024) -#define kReserverHeapContigSpace (64 * 1024) - OSErr nsImageMac::AllocateGWorld(PRInt16 depth, CTabHandle colorTable, const Rect& bounds, GWorldPtr *outGWorld) { *outGWorld = nsnull; @@ -496,6 +493,9 @@ OSErr nsImageMac::AllocateGWorld(PRInt16 depth, CTabHandle colorTable, const Rec // Quick and dirty check to make sure there is some memory available. // GWorld allocations in temp mem can still fail if the heap is totally // full, because some stuff is allocated in the heap + const long kReserveHeapFreeSpace = (256 * 1024); + const long kReserverHeapContigSpace = (128 * 1024); + long totalSpace, contiguousSpace; ::PurgeSpace(&totalSpace, &contiguousSpace); // this does not purge memory! diff --git a/mozilla/widget/src/mac/nsToolkit.cpp b/mozilla/widget/src/mac/nsToolkit.cpp index c1d61a9a2f3..583b1cd2bd1 100644 --- a/mozilla/widget/src/mac/nsToolkit.cpp +++ b/mozilla/widget/src/mac/nsToolkit.cpp @@ -329,17 +329,19 @@ void nsMacMemoryCushion::RepeatAction(const EventRecord &aMacEvent) { if (!RecoverMemoryBuffer(kMemoryBufferSize)) { + // NS_ASSERTION(0, "Failed to recallocate memory buffer. Flushing caches"); // until imglib implements nsIMemoryPressureObserver (bug 46337) // manually flush the imglib cache here nsCOMPtr imageManager = do_GetService(kImageManagerCID); if (imageManager) { - imageManager->FlushCache(1); + imageManager->FlushCache(1); // flush everything } } if (!RecoverMemoryReserve(kMemoryReserveSize)) { + // NS_ASSERTION(0, "Failed to recallocate memory reserve. Flushing caches"); nsMemory::HeapMinimize(PR_TRUE); } } @@ -351,7 +353,7 @@ Boolean nsMacMemoryCushion::RecoverMemoryReserve(Size reserveSize) if (*sMemoryReserve != nsnull) return true; // everything is OK ::ReallocateHandle(sMemoryReserve, reserveSize); - if (::MemError() != noErr) return false; + if (::MemError() != noErr || !*sMemoryReserve) return false; return true; } @@ -359,9 +361,12 @@ Boolean nsMacMemoryCushion::RecoverMemoryBuffer(Size bufferSize) { if (!mBufferHandle) return true; // not initted yet if (*mBufferHandle != nsnull) return true; // everything is OK - + ::ReallocateHandle(mBufferHandle, bufferSize); - if (::MemError() != noErr) return false; + if (::MemError() != noErr || !*mBufferHandle) return false; + + // make this purgable + ::HPurge(mBufferHandle); return true; }