that is called whenever startApp() is called. In almost all cases, this
starts a new game thread without checking for an existing game thread
or storing a reference to the game thread at class scope so that it can be
shut down in a well-defined manner.
TIP : Always keep a class-scoped reference to the game thread to
control its behavior.
To help clarify these issues, try the following exercises:
1. Use the Sun WTK (or whatever IDE you prefer) to start the GhostPong
MIDlet and let it run for a few minutes. You can quickly see the
degradation in performance as more and more Sprite instances are
created. Even though all references to these are removed, there are
simply too many allocated too quickly for the garbage collection
thread to keep up.
Install the MIDlet on a Symbian OS phone (by cable, Bluetooth
transfer or PC Suite software). Start the game and then move it into
the background. Assuming your phone is not in silent mode, you
can hear the game continuing to execute in the background, happily
consuming battery power, CPU cycles, RAM and delivering a bizarre
user experience. Moving the MIDlet back into the foreground in fact
triggers a new game thread instance and very quickly you have a
process with a number of unmanaged threads.
TIP : Where possible, try to reuse objects by using a managed pool of
Symbian OS is a fully multitasking operating system which means that
Java ME MIDlets need to be designed to acquire and release resources as
they are moved in and out of the foreground. For an excellent discussion
on this the reader is referred to Section 3.5.1, Section 4.5 and [de Jode
8.3 MIDP 2.0 Game API Core Concepts
In Chapter 2, we ran through descriptions of the packages and classes
that make up the Game API. The aim of this section is to detail a number
of features it provides, to show how it aids game development on mobile
phones. The MIDP 2.0 Game API supplies a rich game development
framework. A lot of the functionality was incorporated into the MIDP 2.0
specification as a result of real-world experiences writing early Java ME