|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||
java.lang.Objectice.util.memory.MemoryManager
This object keeps track of current memory usage. It is very important that each well-behaving pilot calls isLowMemory() method of this class before allocating substantial amount of memory. And if the method returns true - the pilot should quite as fast as possible cleaning up the resources it has been using.
This approach is much better than just waiting for OutOfMemory exception to happen. Since when such an exception happens it is usually too late to do anything as the system is really out of memory.
An application can ovverride this implementation to add more robust memory recovery. So for example when the system is low on memory the application can try to close other applications etc.
To ensure the proper usage of the memory manager in the browser, the application MUST specify the absolute maximum amount of memory on java heap. Normally this value is given to the JVM with '-mx' option. Since there is no way to extract that value from JVM the browser should be given that value. You can use either the API calls or system properties: ice.browser.minMemory and ice.browser.maxMemory.
| Field Summary | |
protected long |
maxMemory
|
protected long |
minMemory
|
protected Runtime |
runtime
|
| Constructor Summary | |
protected |
MemoryManager()
|
| Method Summary | |
boolean |
canAllocate(int bytes)
Will return true if the system is not in a low memory condition after allocation of specified number of bytes. |
static MemoryManager |
getInstance()
|
long |
getMaxMemory()
Get maximum amount of jvm heap. |
long |
getMinMemory()
Get the minimum amount of memory |
boolean |
isLowMemory()
Check whether the runtime is low on memory. |
static void |
setInstance(MemoryManager mem)
|
void |
setMaxMemory(long m)
Set the maximum amount of jvm heap. |
void |
setMinMemory(long m)
Set the minimum amout of memory. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
protected final Runtime runtime
protected long minMemory
protected long maxMemory
| Constructor Detail |
protected MemoryManager()
| Method Detail |
public static void setInstance(MemoryManager mem)
public static MemoryManager getInstance()
public void setMinMemory(long m)
public long getMinMemory()
public void setMaxMemory(long m)
public long getMaxMemory()
public boolean canAllocate(int bytes)
public boolean isLowMemory()
|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||