Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (513)
Games in Android Showcase (120)
games submitted by our members
Games in WIP (577)
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  
  Removed..  (Read 1698 times)
0 Members and 1 Guest are viewing this topic.
Offline NewOnJava

Junior Duke




1970 born Java game hobbyer.


« Posted 2009-08-23 17:01:31 »

Removed..
Offline bienator

Senior Duke




OutOfCoffeeException


« Reply #1 - Posted 2009-08-23 17:30:13 »

hi,
VisualVM helps in such situations. It has a Visual GC plugin (available via Tools->Plugins) which visualizes heap distribution. Heapdumps can also help to see what is going on in the heap.

As a initial estimation you should give the VM at least 30% more heap (xmx) as the VM would require right after a full garbage collection.

Offline NewOnJava

Junior Duke




1970 born Java game hobbyer.


« Reply #2 - Posted 2009-08-23 18:10:42 »

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

JGO Coder


Medals: 10



« Reply #3 - Posted 2009-08-23 20:11:27 »

No idea why it needs so much memory, you should profile it using the memory profiler in NetBeans or Ecliopse.

If your not using either of these IDEs (and your IDE doesn't allow you to do this) then use the JVisualVM app located in the JDK folder on your PC (on my PC it's at: C:\Program Files\Java\jdk1.6.0_14\bin\jvisualvm.exe). Run it, then run your game, then switch to JVisualVM, on the left your game should be listed, select it, select the 'Profiler' tab, then click 'Memory'.

It should start displaying results straight away, but I'd advise pressing stop after a while. It will list the amount of bytes that objects take up and how many objects there are. One thing to bear in mind is that things like images and sound take up very little space. It's the byte arrays inside that take up the memory.

Offline cylab

JGO Ninja


Medals: 52



« Reply #4 - Posted 2009-08-24 00:19:31 »


( My restarting is just first set my game class to null and then give it a "gameclass game = new gameclass()" ).


You probably are holding a static reference in your gameclass. So when nulling game, you won't automatically release the resources you have loaded, because they are somehow linked with the static object. Since all static references are hold by the class itself and not the instance (you create with new ...), the resources can't be freed.

Either that or you are handing over your resources to some system (like swing), that is doing something like the above. I had much trouble with memory leaks when using buttons in swing...

Mathias - I Know What [you] Did Last Summer!
Offline zoto

Senior Duke


Medals: 4



« Reply #5 - Posted 2009-08-25 08:46:00 »

Why not add a reset method to the gameclass instead of recreating it? I implement this by having each entity have a re spawn method that's called when the game resets. It basically heals the entity and puts them back at their starting location, cancel spells casting, etc.
Offline Eli Delventhal

JGO Kernel


Medals: 42
Projects: 11
Exp: 10 years


Game Engineer


« Reply #6 - Posted 2009-08-25 20:01:33 »

Swing will screw you over in terms of image memory, as will Java2D. A lot of the time you just can't do anything about it other than looking for other options to represent everything.  Undecided

See my work:
OTC Software
Offline JAW

Senior Duke


Medals: 2



« Reply #7 - Posted 2009-08-25 20:27:28 »

I'll use this thread because I have a similar question. For example when I think about a game like worms, that allows pixel based manipulation of the level and seems to be based on an image. When creating a BufferedImage big enough to span a few screens, you quickly have a big file. For example 3000 x 2000 pixels, which is about 3 screens wide and 2 screens high, using the default 4 byte per pixel RGBA, takes 22 MB.

I am wondering, if it is possible to store images in a compressed format, like jpeg, and only decode the visible part of it, so that the in memory impact of big images is smaller like a few MB.

-JAW
Offline Eli Delventhal

JGO Kernel


Medals: 42
Projects: 11
Exp: 10 years


Game Engineer


« Reply #8 - Posted 2009-08-25 22:17:24 »

Nothing to do other than tile a bunch of images, unfortunately. 3000 x 2000 is pretty big, though. Typically you'd just have a small one then blow it up to fill the screen. That's why the resolution in Worms games is always so low.

See my work:
OTC Software
Offline JL235

JGO Coder


Medals: 10



« Reply #9 - Posted 2009-08-26 00:56:07 »

Jaw, I'd advise building some sort of custom level format to state how the level should be painted and if it's painted or not. Perhaps splitting the level up into a grid say 300x200, and each grid section either says it's filled (i.e. solid ground), empty or it contains a 10x10 array containing the level information for each pixel in that grid section.

In theory it should be far cheaper to represent empty space and solid ground, which hopefully will make up a good percentage of most levels. The graphics could then just be smaller images.

On the other hand 22mb these days isn't that much memory.

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

Senior Duke


Medals: 2



« Reply #10 - Posted 2009-08-26 19:49:18 »

Well I thought about maybe loading the raw bytes of a jpeg and decode it on the fly and use only the required portion. But the idea of splitting might be even better, splitting the image into several images of a few hundred pixels wide. I'd just need to reencode unused image parts into jpeg or compressed binary data.

But actually, you are right there too, nowadays Gigabytes of Ram are typical. I should just go ahead an do something, and measure and optimize afterwards. One should not try to optimize beforehand, for you never know, if the optimization is needed at all.

-JAW
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.

Longarmx (52 views)
2014-10-17 03:59:02

Norakomi (43 views)
2014-10-16 15:22:06

Norakomi (33 views)
2014-10-16 15:20:20

lcass (38 views)
2014-10-15 16:18:58

TehJavaDev (68 views)
2014-10-14 00:39:48

TehJavaDev (68 views)
2014-10-14 00:35:47

TehJavaDev (60 views)
2014-10-14 00:32:37

BurntPizza (73 views)
2014-10-11 23:24:42

BurntPizza (45 views)
2014-10-11 23:10:45

BurntPizza (86 views)
2014-10-11 22:30:10
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

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06
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!