Visit Mozilla.org

nsIMemory

From MDC

« XPCOM API Reference

Contents

[edit] Summary

The nsIMemory interface represents a generic memory allocator.

#include "nsIMemory.h"

[scriptable, uuid=(59e7e77a-38e4-11d4-8cf5-0060b0fc14a3)]
interface nsIMemory : nsISupports { ... };

[edit] Methods

alloc
Allocates a block of memory of a particular size.
realloc
The realloc function reallocates a block of memory to a new size.
free
The free method frees a previously allocated block of memory.
heapMinimize
The heapMinimize method attempts to shrink the size of the heap.
isLowMemory
The isLowMemory method determines if we are in a low-memory situation.

[edit] Remarks

nsIMemory is used to allocate and deallocate memory segments from a heap. The implementation is free to define the heap. NS_GetMemoryManager returns the global nsIMemory instance.

An nsIMemory implementation may be capable of monitoring heap usage. Moreover, a mechanism exists by which a client can receive notifications about 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 notifications that can occur. These types will be passed as the aData parameter of the of the "memory-pressure" notification:

"low-memory
This will be passed as the value of aData when a low-memory condition occurs (not necessarily an out-of-memory condition).
"heap-minimize
This will be passed as the value of aData when an explicit call to heapMinimize was made.
"alloc-failure
This will be passed as the value of aData when an out-of-memory condition occurs.

When a nsIMemory instance notifies memory pressure observers, it passes itself as the aSubject parameter in the call to nsIObserverService::notifyObservers. This allows nsIObserver implementations to observe multiple nsIMemory instances and determine the source of memory pressure notifications.

[edit] History

This interface was frozen for Mozilla 0.9.6. See bug 99151 for details.

[edit] See Also

NS_GetMemoryManager, nsIObserverService::notifyObservers, nsIObserver, nsIObserverService