Results 1 to 16 of 16
  1. #1
    Join Date
    Aug 2014
    Posts
    9
    Rep Power
    0

    Question Game using up all my (RAM).

    I don't know if this complies with java or eclipse but I'm using java (of course),eclipse,and libgdx... I'm making a 2D game and I have the screen and the texture for the screen and when I run it it pops up and everything works fine until I see my ram meter start rising and if I keep the screen up it continues to rise.Does anyone know why this is happening?Also I check how much ram eclipse was suppose to use and it was -Xms40m and -Xmx512m.
    Last edited by DeathByFire223; 08-01-2014 at 07:12 AM.

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,016
    Rep Power
    20

    Default Re: Game using up all my (RAM).

    You're holding onto some object that you probably should be allowing the garbage collector to collect.

    Look up how to take a heap dump, then use something like MAT (this is an eclipse plugin) or jhat (which comes with the JDK) to analyse that dump file. It'll take a bit of digging, but one or the other should give you an idea of what object in your code is causing the problem. You'll need to work up a bit to find the root cause, as the immediate culprit will be some sort of primitive array or String array, and you'll want to know what actual class that you use owns those.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  3. #3
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,030
    Rep Power
    6

    Default Re: Game using up all my (RAM).

    ... I don't see an actual problem here. Does the application actually error out with an outofmemory? Does it become slower? Because so far I only see "My application uses memory". Yeah, that's quite normal.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  4. #4
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,541
    Blog Entries
    7
    Rep Power
    20

    Default Re: Game using up all my (RAM).

    If you specified -Xmx512m 512MB is all that is taken by the JVM; i.e. it can't eat all your RAM. The JVM is free however to do with that 512MB what it wants. Normally it eagerly eats it all until the garbage collector wakes up; possibly this is what you saw or possibly some sub process sneakily ate all the other RAM behind the JVM back ...

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  5. #5
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,030
    Rep Power
    6

    Default Re: Game using up all my (RAM).

    I must add that in this case it is not as simple as that; LibGDX is used, which means LWJGL is used, which means that a large pile of JNI is in use to talk to the native OpenGL and OpenAL APIs and lots of native buffers are created. In this case memory usage is not only what is claimed for the Java heap.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  6. #6
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,541
    Blog Entries
    7
    Rep Power
    20

    Default Re: Game using up all my (RAM).

    Quote Originally Posted by gimbal2 View Post
    I must add that in this case it is not as simple as that; LibGDX is used, which means LWJGL is used, which means that a large pile of JNI is in use to talk to the native OpenGL and OpenAL APIs and lots of native buffers are created. In this case memory usage is not only what is claimed for the Java heap.
    Erm, yes, that's what I wrote (see reply #4)

    kind regards,

    Jos (or was it the invisible ink again?)
    cenosillicaphobia: the fear for an empty beer glass

  7. #7
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,030
    Rep Power
    6

    Default Re: Game using up all my (RAM).

    Okay, if you say so :)
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  8. #8
    Join Date
    Aug 2014
    Posts
    9
    Rep Power
    0

    Default Re: Game using up all my (RAM).

    Quote Originally Posted by gimbal2 View Post
    ... I don't see an actual problem here. Does the application actually error out with an outofmemory? Does it become slower? Because so far I only see "My application uses memory". Yeah, that's quite normal.
    it becomes slower when the ram goes to 99%

  9. #9
    Join Date
    Aug 2014
    Posts
    9
    Rep Power
    0

    Default Re: Game using up all my (RAM).

    Quote Originally Posted by JosAH View Post
    If you specified -Xmx512m 512MB is all that is taken by the JVM; i.e. it can't eat all your RAM. The JVM is free however to do with that 512MB what it wants. Normally it eagerly eats it all until the garbage collector wakes up; possibly this is what you saw or possibly some sub process sneakily ate all the other RAM behind the JVM back ...

    kind regards,

    Jos
    how would I add a garbage collector?I'm not to experienced with java.Also should i put the code in?

  10. #10
    jim829 is online now Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    3,620
    Rep Power
    5

    Default Re: Game using up all my (RAM).

    Quote Originally Posted by DeathByFire223 View Post
    how would I add a garbage collector?
    You don't. It's already running.

    Regards,
    Jim
    The Java™ Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

  11. #11
    Join Date
    Aug 2014
    Posts
    9
    Rep Power
    0

    Default Re: Game using up all my (RAM).

    Quote Originally Posted by jim829 View Post
    You don't. It's already running.

    Regards,
    Jim
    Then how do I fix it?

  12. #12
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,541
    Blog Entries
    7
    Rep Power
    20

    Default Re: Game using up all my (RAM).

    Quote Originally Posted by DeathByFire223 View Post
    Then how do I fix it?
    You gave 512MB (-Xmx512m) to the JVM so that's how much memory it is using. The other libraries (not Java) take all the rest, so this is not a Java problem anymore. You have to use gdb, or even adb to dig through that native code; good luck.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  13. #13
    Join Date
    Aug 2014
    Posts
    9
    Rep Power
    0

    Default Re: Game using up all my (RAM).

    Quote Originally Posted by JosAH View Post
    You gave 512MB (-Xmx512m) to the JVM so that's how much memory it is using. The other libraries (not Java) take all the rest, so this is not a Java problem anymore. You have to use gdb, or even adb to dig through that native code; good luck.

    kind regards,

    Jos
    So I would have to go through the native code with the debugger?also what would I see that I would have to fix?

  14. #14
    gimbal2 is offline Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    4,030
    Rep Power
    6

    Default Re: Game using up all my (RAM).

    I think that's going too far. How big is your game? If its not too big yet, I'd consider going over to java-gaming.org and asking for help there. One of the main developers of LibGDX also visits there if I am not mistaken.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  15. #15
    Join Date
    Aug 2014
    Posts
    9
    Rep Power
    0

    Default Re: Game using up all my (RAM).

    Quote Originally Posted by gimbal2 View Post
    I think that's going too far. How big is your game? If its not too big yet, I'd consider going over to java-gaming.org and asking for help there. One of the main developers of LibGDX also visits there if I am not mistaken.
    Yeah my game does only have the main menu background and that's it.so thanks for the advice.

  16. #16
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,016
    Rep Power
    20

    Default Re: Game using up all my (RAM).

    Ohhhh.
    I interpreted "continues to rise" as "eventually throws an Out Of Memory".
    I really must stop extrapolating...
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Similar Threads

  1. Replies: 2
    Last Post: 03-03-2014, 06:48 PM
  2. Replies: 4
    Last Post: 07-08-2012, 09:07 AM
  3. Replies: 1
    Last Post: 06-02-2011, 09:29 AM
  4. Replies: 2
    Last Post: 08-05-2010, 04:49 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •