How much memory consumes my java application ?

I don’t quite understand memory usage in java. When I start my application, I debug 3 pieces of info to figure out what are they REALLY representing :
Runtime.getRuntime().totalMemory() —> 31 MB
Runtime.getRuntime().freeMemory() —> 13 MB
Runtime.getRuntime().maxMemory() —> 66 MB

Now, in windows task manager my javaw process is consuming 244 MB of RAM?
My game is made in openGL by lwjgl. Am I right to suppose that what Runtime.getRuntime().totalMemory() gave me is amount of java objects that occupy memory, and all that part up to 244 MB are textures loaded with GL11.glGenTextures?

The amount of memory shown in Task Manager also includes the memory mapped in for the C portion of the JVM, and the stacks for each thread, and also all the DLLs loaded (including OpenGL), and all the direct bytebuffers you’ve allocated, and also all the textures you’ve uploaded to GL. The bit that Runtime returns refers solely to the Java Object heap, which is sized according to your commandline arguments with -Xmx / -Xms.

Cas :slight_smile:

Which memory size column in Task Manager are you refering to? Note that the VM size column also includes memory which has been reserved but not allocated (i.e. there is no real memory used).

Thanks, Cas, that was really heplfull !

Mark, I was refering to process “named” javaw that is launched when I start my game…

Mark is drawing your attention to the fact that there are 2 amounts of memory shown in Task Manager; the normal one is “physical memory” in use, and the other one you might want to add is “virtual memory”, which is memory allocated but not currently in the application’s working set. Physical memory’s probably the one you need to keep an eye on :wink:

Cas :slight_smile:

Cas, I’m not shure if we understand each other. I know where to look for amounts of my physical memory (Total, available…) and virtual memory. That info is under “Performance” card. But under “Processes” card one can find how much memory (“Mem Usage” column) uses one single process. And that is what really interested me. Not overall memory usage of all runing applications, but my specific one - which is as I already said named “javaw.exe” (they always do if they are trigerred with javaw command).

If you look on the second tab of task manager, you can go to the menu and choose Select Columns. There you will be able to add the column showing how much virtual memory your process has allocated.

Cas :slight_smile:

Indeed! Every day you can learn something new :slight_smile: