You are currently viewing a snapshot of www.mozilla.org taken on April 21, 2008. Most of this content is highly out of date (some pages haven't been updated since the project began in 1998) and exists for historical purposes only. If there are any pages on this archive site that you think should be added back to www.mozilla.org, please file a bug.
This interface is used to allocate and deallocate memory. It also provides for notifications in low-memory situations.
A client that wishes to be notified of low memory situations (for example, because the client maintains a large memory cache that could be released when memory is tight) should register with the observer service (see
nsIObserverService) using the topic memory-pressure. There are three specific types of notications that can occur. These types will be passed as the
aDataparameter of the "memory-pressure" notification:low-memory: This will be passed as the extra data when the pressure observer is being asked to flush for low-memory conditions.
heap-minimize: This will be passed as the extra data when the pressure observer is being asked to flush because of a heap minimize call.
alloc-failure: This will be passed as the extra data when the pressure observer has been asked to flush because a
This interface is partially scriptable.
Allocates a block of memory of a particular size. If the memory cannot be allocated (because of an out-of-memory condition),
nullis returned. This method is not scriptable.
Syntax:voidPtr nsIMemory::alloc(in size_t size)
Reallocates a block of memory to a new size. This method is not scriptable.
Syntax:voidPtr nsIMemory::realloc(in voidPtr ptr, in size_t newSize)
null, this function behaves like
sis the size of the block to which
ptrpoints, the first
min(s, size)bytes of
ptr's block are copied to the new block. If the allocation succeeds,
ptris freed and a pointer to the new block returned. If the allocation fails,
ptris not freed and
nullis returned. The returned value may be the same as
Frees a block of memory.
Nullis a permissible value, in which case nothing happens. This method is not scriptable.
Syntax:void nsIMemory::free(in voidPtr ptr)
Attempts to shrink the heap. This method is scriptable.
Syntax:void nsIMemory::heapMinimize(in boolean immediate)
immediate:If the value is
TRUE, heap minimization will occur immediately if the call was made on the main thread. If the value is
FALSE, the flush will be scheduled to happen when the app is idle.
Indicates a low-memory situation (what constitutes low-memory is platform dependent). This can be used to trigger the memory pressure observers.
| Written by:Ellen Evans | Comments, questions, complaints?