Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (539)
Games in Android Showcase (132)
games submitted by our members
Games in WIP (601)
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 1864 times)
0 Members and 1 Guest are viewing this topic.
Offline 8bitooze

Senior Newbie





« Posted 2011-01-26 20: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: 840
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #1 - Posted 2011-01-26 21: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
Offline kappa
« League of Dukes »

JGO Kernel


Medals: 81
Projects: 15


★★★★★


« Reply #2 - Posted 2011-01-26 21: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 21: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: 81
Projects: 15


★★★★★


« Reply #4 - Posted 2011-01-26 21: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

« JGO Spiffy Duke »


Medals: 434
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #5 - Posted 2011-01-26 22: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.

 

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

The first screenshot will be displayed as a thumbnail.

rwatson462 (30 views)
2014-12-15 09:26:44

Mr.CodeIt (20 views)
2014-12-14 19:50:38

BurntPizza (42 views)
2014-12-09 22:41:13

BurntPizza (76 views)
2014-12-08 04:46:31

JscottyBieshaar (37 views)
2014-12-05 12:39:02

SHC (51 views)
2014-12-03 16:27:13

CopyableCougar4 (48 views)
2014-11-29 21:32:03

toopeicgaming1999 (115 views)
2014-11-26 15:22:04

toopeicgaming1999 (103 views)
2014-11-26 15:20:36

toopeicgaming1999 (30 views)
2014-11-26 15:20:08
Resources for WIP games
by kpars
2014-12-18 10:26:14

Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
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!