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
This commit is contained in:
@@ -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;
|
||||
|
||||
|
||||
@@ -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!
|
||||
|
||||
|
||||
@@ -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<nsIImageManager> 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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user