The Java ME SDK 3.0 includes some tools for this. They are not available in the IDE but has to be started from the command line. So you open two command line windows. In the first you start your midlet:
C:\Java_ME_platform_SDK_3.0\bin>emulator.exe -Xdevice:DefaultCldcPhone1 -Xdebug -Xrunjdwp:transport=dt_socket,suspend=n,server=y,address=51307 -Xdescriptor:[jadfile]
This should start the emulator with your midlet. I choose the DefaultDldcPhone1 which is configured to have 4 MB of heap. You can change that in the device properties if you want to.
In your second command window you start the memory profiler:
memory-profiler.exe -host 127.0.0.1 -port 51307
This should open up the memory profiler window. You then press Connect to cennect to your emulator instance.This will take a while but then you get a window something like this:
Now you press resume and run your application and try to recreate your memory problems. After that you press Pause in the memory tool. This will cause the tool to get a memory dump from your runing application. You will get a memory map at the top and at the bottom left a list of classes and primitives. You can select a class in the list and see what instances exist. It is however quite difficult to find information this way. Better is to use the statistics button. This will get you a window something like this:
The data is:
- class name or primitive. a [ means 'array of'
- object number (or number of objects rather)
- average size
- % of heap
- live %
- old generation %