Java-Gaming.org
Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
Featured games (78)
games approved by the League of Dukes
Games in Showcase (406)
games submitted by our members
Games in WIP (293)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Java Applet Memory Hog  (Read 1306 times)
0 Members and 1 Guest are viewing this topic.
Offline 8bitooze

Senior Newbie





« Posted 2011-01-26 21:42:13 »

I am creating a simple vector based game and just noticed something. My basic applet uses 22mb of memory! I learned this by opening the task manager and looking at the process java.exe on my windows xp machine. All my applet does it clear the screen and draw a (int)320 by (int)20 rectangle. The applets size is 320 by 240 so it can't possibly be using that much memory for such a small screen. Is this correct or am i missing something? If this is correct is this going to impact my game in any way? Any assistance would be greatly appreciated.

Sincerely,

8BitOoze

[size=3]8BitOoze[/size]
Offline Riven
« League of Dukes »

JGO Overlord


Medals: 438
Projects: 4


Hand over your head.


« Reply #1 - Posted 2011-01-26 22:11:39 »

The Java Virtual Machine has a heap on which it allocates objects. The JVM starts out with a rather large heap, which is nearly empty. Once you start creating new objects, it will fill the heap. All this time the TaskManager will say your JVM takes 22mb, because it only sees the heap the JVM has created.

Besides that, yes, a typical Java application requires a bit more memory than your average C application. Nothing to worry about though, it's certainly not extreme. Every object has a 8 byte header, so you can do the math: an int is still 4 byte, and a float[100] is still 400 bytes plus object overhead. As the JVM doesn't free each object independently, you'll always have a fair amount of 'garbage' in the heap. Don't worry, the JVM can move objects around, 'compact' them, and shrink the heap, when it notices you released a lot of objects.

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Projects: Revenge of the Titans, Titan Attacks, Droid Assault, and Ultratron
Offline kappa
« League of Dukes »

JGO Kernel


Medals: 50
Projects: 15


★★★★★


« Reply #2 - Posted 2011-01-26 22:24:51 »

Also since plugin2 you can set the heap size for applets using Xmx or Xms parameters. By default each applet has a maximum heap size of 64mb, so if you want a small heap and you know your app won't go over it, you can set it as follows:


1  
2  
// set a maximum heap size of 16mb, default is 64mb
<PARAM name="java_arguments" value="-Xmx16m">

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline 8bitooze

Senior Newbie





« Reply #3 - Posted 2011-01-26 22:39:19 »

Also since plugin2 you can set the heap size for applets using Xmx or Xms parameters. By default each applet has a maximum heap size of 64mb, so if you want a small heap and you know your app won't go over it, you can set it as follows:


1  
2  
// set a maximum heap size of 16mb, default is 64mb
<PARAM name="java_arguments" value="-Xmx16m">


Ok, I will try that in the next update to my game and see if it helps manage the memory better.

The Java Virtual Machine has a heap on which it allocates objects. The JVM starts out with a rather large heap, which is nearly empty. Once you start creating new objects, it will fill the heap. All this time the TaskManager will say your JVM takes 22mb, because it only sees the heap the JVM has created.

Besides that, yes, a typical Java application requires a bit more memory than your average C application. Nothing to worry about though, it's certainly not extreme. Every object has a 8 byte header, so you can do the math: an int is still 4 byte, and a float[100] is still 400 bytes plus object overhead. As the JVM doesn't free each object independently, you'll always have a fair amount of 'garbage' in the heap. Don't worry, the JVM can move objects around, 'compact' them, and shrink the heap, when it notices you released a lot of objects.
Just wondering cause if an applet used much memory for a simple display without the above info, as a  consumer i would've freaked out.

Sincerely,

8BitOoze

[size=3]8BitOoze[/size]
Offline kappa
« League of Dukes »

JGO Kernel


Medals: 50
Projects: 15


★★★★★


« Reply #4 - Posted 2011-01-26 22:44:14 »

Just wondering cause if an applet used much memory for a simple display without the above info, as a  consumer i would've freaked out.

22mb isn't really that bad for a VM running with libraries like AWT, Java2D, etc. A typical youtube video can easily use over 50mb.
Offline princec
« League of Dukes »

JGO Kernel


Medals: 196
Projects: 3


Eh? Who? What? ... Me?


« Reply #5 - Posted 2011-01-26 23:23:06 »

Indeed, an empty tab in Chrome takes up something like 9mb. RAM's not the valuable stuff it once was...

Cas Smiley

Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
 
Browse for soundtracks for your game!

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

The invasion has landed! On Mars! And you're there to beat 'em!
cubemaster21 (73 views)
2013-05-17 21:29:12

alaslipknot (85 views)
2013-05-16 21:24:48

gouessej (114 views)
2013-05-16 00:53:38

gouessej (109 views)
2013-05-16 00:17:58

theagentd (120 views)
2013-05-15 15:01:13

theagentd (109 views)
2013-05-15 15:00:54

StreetDoggy (154 views)
2013-05-14 15:56:26

kutucuk (176 views)
2013-05-12 17:10:36

kutucuk (173 views)
2013-05-12 15:36:09

UnluckyDevil (182 views)
2013-05-12 05:09:57
Complex number cookbook
by Roquen
2013-04-24 12:47:31

2D Dynamic Lighting
by Oskuro
2013-04-17 16:46:12

2D Dynamic Lighting
by Oskuro
2013-04-17 16:45:57

2D Dynamic Lighting
by Oskuro
2013-04-17 16:23:20

Noise (bandpassed white)
by Roquen
2013-04-05 17:36:01

Noise (bandpassed white)
by Roquen
2013-04-03 16:17:38

Java Data structures
by Roquen
2013-03-29 13:21:12

Topic Request
by kutucuk
2013-03-22 21:42:01
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!
Page created in 0.113 seconds with 20 queries.