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 (405)
games submitted by our members
Games in WIP (289)
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  
  [HELP] Memory Leak (Simple Game)  (Read 1498 times)
0 Members and 1 Guest are viewing this topic.
Offline Canownueasy

Junior Newbie




There's no place like localhost


« Posted 2012-02-19 10:22:33 »

I am getting a huge memory leak in my very simple game.

I have tried profiling the VM, and apparently there are many, many integer arrays (int[])

Here is the source, please take a look, it is a simple game: http://dl.dropbox.com/u/26438996/Block%20Evader.zip
Offline jammas615

Junior Member


Projects: 1



« Reply #1 - Posted 2012-02-19 10:32:26 »



...Oh my God. :0

Where are these int arrays?

Offline Canownueasy

Junior Newbie




There's no place like localhost


« Reply #2 - Posted 2012-02-19 10:37:23 »



...Oh my God. :0

Where are these int arrays?
I have no idea. Cry
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline jammas615

Junior Member


Projects: 1



« Reply #3 - Posted 2012-02-19 10:48:04 »

Debugging and stepping through your code can be helpful and good to get used to.

If i was you, i would take a look at this section:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
while (true) {
            Enemy enemy = world.getEnemies().get(Misc.random(world.getEnemies().size() - 1));
            Direction dir = Direction.values()[Misc.random(Direction.values().length-1)];
            for (int i = 0; i < 15; i++) {
               enemy.move(dir);
               Thread.sleep(10);
            }
            Thread.sleep(10);

         }

I'm retarded, don't worry. :/

Offline Canownueasy

Junior Newbie




There's no place like localhost


« Reply #4 - Posted 2012-02-19 10:50:24 »

I do not think so. If I comment that out, I get the same results.

I figured out what's hogging the memory: DataBufferInt

Here is some info I found: http://www.symphonious.net/2007/04/26/japplet-memory-leaks/
Offline Stranger

Junior Member


Medals: 3



« Reply #5 - Posted 2012-02-19 12:17:37 »

I think there's no need to create image on every paint.
Create it once and then fillrect with background color if any.

1  
2  
3  
4  
5  
6  
7  
@Override
public void paint(Graphics g) {
    dbImage = createImage(getWidth(), getHeight());
    paintWorld(dbImage.getGraphics());
    g.drawImage(dbImage, 0, 0, this);
    repaint();
}

Anton
Online ra4king

JGO Kernel


Medals: 264
Projects: 2


I'm the King!


« Reply #6 - Posted 2012-02-19 19:31:22 »

Yup your problem is the paint method in your Applet class. You are creating a new Image every frame! Create it once and then reuse it.

Also, you shouldn't be calling repaint() every frame, instead you should call it in your game loop.

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!
 
Get high quality music tracks 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 (59 views)
2013-05-17 21:29:12

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

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

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

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

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

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

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

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

UnluckyDevil (174 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.129 seconds with 21 queries.