Sun Microsystems 2 Wireless Office Headset User Manual


 
21
CHAPTER
3
Managing Native Resources
The typical device is constrained in the amount of resources, such as memory or
sockets, that it has available. When the Java Wireless Client software is running on a
device, it is often provided with a fixed set of resources that it cannot exceed. In a
single-tasking environment, a single MIDlet has access to all of the available
resources. However, in a multitasking environment, multiple MIDlets might have to
compete among themselves for this fixed set of resources.
For example, assume that the Java Wireless Client software has 600 kilobytes of heap
memory, and that MIDlet A requires 400 kilobytes and MIDlet B requires 300
kilobytes. The user can run either MIDlet A alone or MIDlet B alone, and each works
fine. However, if MIDlet A is running and the user starts MIDlet B, MIDlet B might
receive an out-of-memory error.
MIDlets sometimes allocate only some of the memory they need at startup, but
allocate more memory when a certain operation is performed. For example, suppose
MIDlet A is running and consumes 350 kilobytes, and the user starts MIDlet B. At
startup, MIDlet B might consume only 100 kilobytes and might appear to work fine.
However, when the user attempts a particular operation using MIDlet B, it might
allocate the additional 200 kilobytes, causing an out-of-memory error during its
operation. Alternatively, if the user switches to MIDlet A and MIDlet A allocates
more memory, then MIDlet A might receive the out-of-memory error.
This is a difficult problem because each MIDlet might test successfully with the Java
Wireless Client software and work fine when run individually. However, when run
at the same time, the MIDlets could appear to be unstable, receiving out-of-memory
errors at unpredictable times.