Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (542)
Games in Android Showcase (133)
games submitted by our members
Games in WIP (606)
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  
  A ton of primitive types created at runtime  (Read 1661 times)
0 Members and 1 Guest are viewing this topic.
Offline Mike

« JGO Spiffy Duke »


Medals: 88
Projects: 1
Exp: 6 years


Java guru wanabee


« Posted 2011-06-01 15:28:22 »

Hi gurus,

I ran some tests with VisualVM against my server app and for some reason it creates a whole lot of int[] (even though I never create a int[] in my code). Every time a user logs in VisualVM says that about 10MB of int[]s gets created. When running a heap dump they all disappear (due to the gc linked to the heap dump) and they never stay in memory.

If I run eclipse debug with a breakpoint on the first line at the same time as VisualVM the first line on the server 'System.out.println("Starting Server");' generates about 10MB of int arrays.

Did anyone run into something similar before? I also ran some checks and when I don't run the server in debug mode or at the same time as VisualVM it uses a lot less memory (the int[]'s?). What method should I use to get a believable good view of my memory usage? Printing out the runtime.freeMemory sounds like the most reliable way but then I have no insight into what objects are taking up the heap.

Kind regards,
Mike

My current game, Minecraft meets Farmville and goes online Smiley
State of Fortune | Discussion thread @ JGO
Offline CommanderKeith
« Reply #1 - Posted 2011-06-01 15:47:58 »

Hi,

It's probably java2D creating all of the int arrays since they back images.

Using netbeans profiler you can take a snapshot of the heap (a heap dump) and you can see what methods allocate what objects. Maybe give netbeans profiler a spin?

Keith

Offline ra4king

JGO Kernel


Medals: 356
Projects: 3
Exp: 5 years


I'm the King!


« Reply #2 - Posted 2011-06-02 16:09:44 »

You can take a snapshot of the heap in VisualVM too. And this can't be Java2D because, as he states, this is a server app. Do you have some code to show us where you see the int arrays being created?

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

JGO Knight


Medals: 32



« Reply #3 - Posted 2011-06-02 21:16:25 »

If you didn't create the int[]'s then something else is, such as the PrintStream attached to standard out.  This is plausible since it likely buffers its output (although 10M seems excessive).  However, it probably isn't a memory leak since the heap dump gets rid of them.  Java won't GC unless needed and 10M won't really push the memory limits.

Profiling always changes the way your code runs so you must analyze the results carefully, but I wouldn't worry about it.  It is extremely unlikely that you've found memory bugs in the JVM.  One thing to check for, however, is that you're using the server code correctly and not holding onto streams longer than you need to or are forgetting to close them.

I like using Runtime.freeMemory() and System.nanoTime() and the related methods to do course profiling within my code. That way all the JIT optimizations can kick in and I don't have to worry about the profiler messing with things behind my back.  As you've noticed, the information is not as useful or informative, though.

Offline Mike

« JGO Spiffy Duke »


Medals: 88
Projects: 1
Exp: 6 years


Java guru wanabee


« Reply #4 - Posted 2011-06-03 06:27:41 »

Hi,

It's probably java2D creating all of the int arrays since they back images.

Using netbeans profiler you can take a snapshot of the heap (a heap dump) and you can see what methods allocate what objects. Maybe give netbeans profiler a spin?

Keith

It's an server app and as I stated the heap dump never displays anything seeing as the primitive types never stay in memory.

You can take a snapshot of the heap in VisualVM too. And this can't be Java2D because, as he states, this is a server app. Do you have some code to show us where you see the int arrays being created?

System.out.println("Starting Server"); for example, which made no sense until I read...:
If you didn't create the int[]'s then something else is, such as the PrintStream attached to standard out.  This is plausible since it likely buffers its output (although 10M seems excessive).  However, it probably isn't a memory leak since the heap dump gets rid of them.  Java won't GC unless needed and 10M won't really push the memory limits.

Profiling always changes the way your code runs so you must analyze the results carefully, but I wouldn't worry about it.  It is extremely unlikely that you've found memory bugs in the JVM.  One thing to check for, however, is that you're using the server code correctly and not holding onto streams longer than you need to or are forgetting to close them.

I like using Runtime.freeMemory() and System.nanoTime() and the related methods to do course profiling within my code. That way all the JIT optimizations can kick in and I don't have to worry about the profiler messing with things behind my back.  As you've noticed, the information is not as useful or informative, though.

Thanks a ton, I expected that to be the case but it's good to get it confirmed Smiley

My current game, Minecraft meets Farmville and goes online Smiley
State of Fortune | Discussion thread @ JGO
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.

Elsealabs (19 views)
2014-12-28 10:39:27

CopyableCougar4 (20 views)
2014-12-28 02:10:29

BurntPizza (25 views)
2014-12-27 22:38:51

Mr.CodeIt (15 views)
2014-12-27 04:03:04

TheDudeFromCI (20 views)
2014-12-27 02:14:49

Mr.CodeIt (26 views)
2014-12-23 03:34:11

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

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

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

BurntPizza (116 views)
2014-12-08 04:46:31
How do I start Java Game Development?
by gouessej
2014-12-27 19:41:21

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
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!