![]()
Using a Memory Manager
Your application should have a configureable safety buffer of memory because it is not possible to control everything in the JVM. If memory runs out, all behavior becomes unpredictable, and the JVM may malfunction. The memory manager is frequently consulted to see if it is safe to use more memory.
A buffer improves stability in low memory conditions. Parts of the JVM code use Java heap space and cannot be controlled. A large buffer will increase the chances that a low memory condition is detected before other, non-memory managed parts of the JVM use all the memory. However, a larger safety buffer means less space for rendering content.
Creating a Custom Memory Manager
Some hardware platforms have special memory features that can be used to increase performance, or in some cases, must be used to assure stability. The platform can, for example, have partitioned memory with one part for the Java heap and one part for graphics memory or native code. You may want to extend the default memory manager, which manages the Java heap only, to also manage the graphics memory partition, given that there would be an API for doing that in Java for the platform.
Use the following procedure to create a custom memory manager:
- Inherit ice.util.MemoryManager.
- Override the method public boolean canAllocate(int bytes).
- Place your custom memory-checking code in this method, remembering to call super( ).
- In the code of your application, create a new <Custom>MemoryManager( ) and a MemoryManager.setInstance( ), so that the memory manager instantiated is yours and not the default.
Setting Memory Values
The minMemory value, which reflects the safety buffer size, should be adjusted to the size and stability required on the platform. On the platforms tested, 1MB is typically enough.
The maxMemory value should always be lower than or equal to the Java heap size. By setting it lower, you can control how much of the total heap space the browser uses.
Setting a Time Period for Memory Checking
The system property ice.browser.memoryCheck.period can be used to specify the time increments, in milliseconds, that the browser should explicitly check for a low memory condition. If this property is defined as a positive integer and a low memory condition is detected, the method onLowMemory is called for each ice.storm.Pilot instance in the browser.
It may be necessary to define this property if the JVM can use only a limited amount of memory, and the implementation of system Java libraries cannot recover from the java.lang.OutOfMemoryError exception. For more information, see the API documentation for ice.util.memory.MemoryManager.
|
Copyright 2005. ICEsoft Technologies, Inc. http://www.icesoft.com |