Results 1 to 10 of 10
  1. #1
    kammce's Avatar
    kammce is offline Senior Member
    Join Date
    Dec 2010
    Location
    California
    Posts
    194
    Rep Power
    4

    Default 77 Megabytes of int[]

    I was testing out my game project, ApexFaction, and I noticed how much memory it was taking up. So, thinking simply that it must be caused by the images I was using, I optimize my game to store images in a fashion that decreased the amount of memory it used but the amount of data it was using was still gigantic (90 mbs). So, I discover JProfiler, and start using it. I discover that a massive amount of memory is being eaten up by int arrays. 77 - 80 megabytes to be exact.

    I am wondering if anyone else has used JProfiler and could answer some of my questions.

    1. My first question is, is having this much memory consumed by int arrays normal/natural? JProfiler states that I am using 5933 instances of int[]s, but I only use a few in my program. At most, I could expect that I am creating 100 max int arrays in my own objects.
    2. Could the other int arrays be coming from the default java libraries?
    3. Can I do anything about it?
    4. Could there be int[] instances that I can get rid of?
    5. Maybe make them eligible for garbage collection?
    6. Are my attempts to minimize the amount of primitive types in this game be futile?



    If I am not giving enough information, please inform me and I will try to give out more information on my situation.
    My API:
    Java Code:
    cat > a.out || cat > main.class

  2. #2
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,189
    Rep Power
    19

    Default Re: 77 Megabytes of int[]

    At most, I could expect that I am creating 100 max int arrays in my own objects.
    What about int[][] or int[][][]?

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  3. #3
    kammce's Avatar
    kammce is offline Senior Member
    Join Date
    Dec 2010
    Location
    California
    Posts
    194
    Rep Power
    4

    Default Re: 77 Megabytes of int[]

    int[][] = 191
    I know where this object is coming from. I have a object that uses a two dimensional array to store some values.
    int[][][] = 1
    Not too sure where that one is coming from.
    My API:
    Java Code:
    cat > a.out || cat > main.class

  4. #4
    kjkrum's Avatar
    kjkrum is offline Senior Member
    Join Date
    Apr 2011
    Location
    Tucson, AZ
    Posts
    1,058
    Rep Power
    5

    Default Re: 77 Megabytes of int[]

    I think what Darryl is getting it is that an int[][] can be thought of (and in fact is) an array of int[]s.
    Get in the habit of using standard Java naming conventions!

  5. #5
    kammce's Avatar
    kammce is offline Senior Member
    Join Date
    Dec 2010
    Location
    California
    Posts
    194
    Rep Power
    4

    Default Re: 77 Megabytes of int[]

    at most, my int[][] would only be 60 different values total for one whole int[][] array. I create two different objects that holds int[][]. So I have 120 values in total that I know I created. It is a 6x10 bi-dimensional array. If it were int[], there would only be 12 instances of them that is 10 values in length
    My API:
    Java Code:
    cat > a.out || cat > main.class

  6. #6
    kjkrum's Avatar
    kjkrum is offline Senior Member
    Join Date
    Apr 2011
    Location
    Tucson, AZ
    Posts
    1,058
    Rep Power
    5

    Default Re: 77 Megabytes of int[]

    Some of those int[]s could be local variables or otherwise eligible for garbage collection. IIRC, they'd still be listed as using heap memory, but it's guaranteed that all eligible objects will be GCed before an OutOfMemoryError is thrown. I think it's pretty normal for unreachable objects to nearly fill up the heap before the GC runs. Running it takes time, so why run it more often than necessary?
    Get in the habit of using standard Java naming conventions!

  7. #7
    kammce's Avatar
    kammce is offline Senior Member
    Join Date
    Dec 2010
    Location
    California
    Posts
    194
    Rep Power
    4

    Default Re: 77 Megabytes of int[]

    Do you believe that I should look through my code and see what loose int variables I have. Maybe convert them into smaller primitive types. I know I am not using the full amount of the int. I could be using shorts. Is there anyway to make int[] more eligible for GCing? Should I care about this? Is 80mbs of heap and memory allocation from int[] even a problem? I think I am becoming obsessed with optimization!
    My API:
    Java Code:
    cat > a.out || cat > main.class

  8. #8
    kjkrum's Avatar
    kjkrum is offline Senior Member
    Join Date
    Apr 2011
    Location
    Tucson, AZ
    Posts
    1,058
    Rep Power
    5

    Default Re: 77 Megabytes of int[]

    IIRC, smaller primitive types still use the same number of bytes as an int. The only real savings is if you have a bunch of booleans you can convert to a BitSet.

    If you want to find out how much memory your program is actively using, you could try setting the heap size to smaller values until something throws an OutOfMemoryError. Then you could set it a little larger than that and let it run for a while to see if the memory usage grows over time. But generally I don't think you should worry about it. The only downside to an oversized heap full of GC-eligible objects is that it's memory that could be used by some other program.
    Get in the habit of using standard Java naming conventions!

  9. #9
    kammce's Avatar
    kammce is offline Senior Member
    Join Date
    Dec 2010
    Location
    California
    Posts
    194
    Rep Power
    4

    Default Re: 77 Megabytes of int[]

    Alright then. Thank you for your help!
    My API:
    Java Code:
    cat > a.out || cat > main.class

  10. #10
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,442
    Rep Power
    18

    Default Re: 77 Megabytes of int[]

    Get yourself a copy of the Eclipse MAT, and feed your heap dump to it.
    That'll show you exactly where those arrays are coming from.
    Please do not ask for code as refusal often offends.

Posting Permissions

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