Posted by javakiddy
on August 5, 2005 at 9:43 AM PDT
Apologies for the slight off-topic nature of this post, but there doesn't appear to be a dedicated J2ME/MIDP forum.
While recently experimenting with J2ME, I noticed that the current Displayable object is retained by the KVM (or rather the LCDUI) when a MIDlet is paused. I found this out quite by chance, as one of my MIDlets - 'SudokuME' - threw a NullPointerException upon being resumed. Like a good little boy I had re-referenced all unnecessary data when the MIDlet was paused: anything I could reload or reconstruct was ditched. However, the previous Displayable was restored when the MIDlet resumed, except now the data upon which it depended had been GC'd, hence the exception.
The problem here is setting the display (a) doesn't have an immediate effect, and (b) cannot be set to null anyway, as a null parameter merely re-activates the current Displayable (right?) So even if I so a setCurrent(null) inside pauseApp(), it isn't going to release the current display for GC.
Displayable's often house lots of GUI code, and therefore tend to make heavy use references to other objects and data structures. While it would be perfectly possible to add a method to each of my Displayable objects to de-couple all this data, and call it from within pauseApp(), it would be much easier to provide some standard, trusted and easy(!) means by which the current Displayable could be released when the MIDlet is paused - perhaps to be replaced by a inbuilt bare-bones Displayable (as it apparently can never be set to null)?
Perhaps a new method...