Results 1 to 8 of 8
  1. #1
    jwilley44 is offline Member
    Join Date
    Jan 2009
    Posts
    12
    Rep Power
    0

    Default [SOLVED] JVM: Heap out of memory

    Hello,

    I keep running out of memory while running my application in eclipse. I have 7.6 G of available RAM and I have already changed the -Xms128m and -Xmx128m to -Xms7000m and -Xmx7000m respectively in the eclipse.ini file. I am running eclipse Ganymede on Ubuntu 8.10 64 bit. I am also fairly sure that I downloaded eclipse for 64 bit Linux. The Resources on the System Monitor displays that I am only using 3.9 G of my RAM and the application still crashes with an "out of memory message".

    Thanks in advance.

  2. #2
    Steve11235's Avatar
    Steve11235 is offline Senior Member
    Join Date
    Dec 2008
    Posts
    1,046
    Rep Power
    8

    Default

    I use a plug-in called FreeMem that shows Eclipse memory usage and runs gc periodically. That would allow you to monitor how much memory the Eclipse environment is using.

    7,000m of memory is quite a bit... I'm guessing some code somewhere is looping and instantiating objects at an obscene pace.

    Exactly when does this happen?

    When you open a specific editor or tool?

    When you start your own application?

  3. #3
    jwilley44 is offline Member
    Join Date
    Jan 2009
    Posts
    12
    Rep Power
    0

    Default

    First: Thanks for the plug-in tip I have been looking for one to use with eclipse
    Second: I am using the word application liberally, I am actually running a physics simulation.
    I have a specific object, call it A, it contains a primitive long, a List of other objects of type A and List of a different objects of type of B. So far I have been able to create 262144 (64^3) of these objects without a problem but when I try to create more lets say 1000000 of them it runs out of memory. I am not sure how much memory each object takes up and unfortunately I am not near my code to check. When I get home tonight I will look and re-post. But, I seem to remember that when when I created 64^3 of them I think I was only using about 1.5 to 2 G of memory.
    Also, why does java quit when it reaches 3.9 G when almost twice that is available?

    Thanks.

  4. #4
    jwilley44 is offline Member
    Join Date
    Jan 2009
    Posts
    12
    Rep Power
    0

    Default

    Sorry I noticed that I may have been unclear on at least one point.
    When I say that I am using 1.5 to 2 G of memory I mean for the whole simulation not just for those objects.
    I am anxious to try out the plug-in and see exactly how much memory each object uses.

  5. #5
    Steve11235's Avatar
    Steve11235 is offline Senior Member
    Join Date
    Dec 2008
    Posts
    1,046
    Rep Power
    8

    Default

    That's a whopping lot of objects. Also, primitives are created on the stack, not on the heap, so that is an even bigger hit. 4 meg on the stack is a lot.

    3.9 gig is around 2^32 bytes, which probably explains the total memory limitation for a single application.

    I really like Java and Object Oriented languages in general, but they are very inefficient with memory. For what you are doing, you might want to look at straight C (not C++), Fortran (created for crunching numbers), or another specialty language designed for your purpose...

  6. #6
    jwilley44 is offline Member
    Join Date
    Jan 2009
    Posts
    12
    Rep Power
    0

    Default

    Yeah, I was hoping not to have go to back to C, because this specific simulation's structure was well suited for an OOP language. I might try a few more things but I will probably just rewrite the simulation in C. Thanks for your input.

  7. #7
    jwilley44 is offline Member
    Join Date
    Jan 2009
    Posts
    12
    Rep Power
    0

    Default

    OK I talked to one of my friends and he had the solution. I only changed eclipse's memory size and not the JVM's doh! So all I did was: under run, pass in -Xmx7000m into the JVM arguments, easy. But even so it still might be better to work in C for this project.

  8. #8
    neilcoffey is offline Senior Member
    Join Date
    Nov 2008
    Posts
    286
    Rep Power
    7

    Default

    Before switching to C, I'd try and be a bit clearer that it's really going to help you. Yes, there is a slight per-object overhead in Java. But there is also a similar per-allocation overhead in C. You can avoid the per-allocation overhead in C by doing judicious things such as allocating a single array of structs/objects (but not an array of pointers to individual structs/objects). But you could also do judicious things in Java to cut down on memory usage if it's really necessary (e.g. trimming collections to their current size; choosing appropriate structures; in extreme cases, using arrays of primitives or a ByteBuffer to give a single per-object overhead rather than a large number of objects containing primitives).

    Related articles I've written that may be of interest:
    - how to calculate the usage of a Java object

    - How to query the memory usage of a Java object

    - Java equivalent of malloc (and how to use Java buffers)

Similar Threads

  1. JVm Heap memory settings
    By nagesh in forum Advanced Java
    Replies: 2
    Last Post: 09-17-2009, 06:47 PM
  2. Jotm (Java Open Transaction Management)- Heap Memory Issues
    By hariprashanth in forum Advanced Java
    Replies: 0
    Last Post: 12-18-2008, 12:42 PM
  3. Replies: 2
    Last Post: 08-21-2008, 08:33 PM
  4. JVM Heap memory settings
    By nagesh in forum New To Java
    Replies: 1
    Last Post: 08-11-2007, 11:17 PM
  5. Java Heap Out of Memory Error
    By stonkers in forum New To Java
    Replies: 3
    Last Post: 07-17-2007, 05:43 PM

Posting Permissions

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