OutOfMemoryError

can anyone shed light on these OutOfMemoryErrors? i'm getting these crash reports occasionally from users.



i'm currently using these VM arguments: -XX:MaxDirectMemorySize=500m -Xms512m -Xmx512m


java.lang.OutOfMemoryError
   sun.misc.Unsafe.allocateMemory(Native Method)
   java.nio.DirectByteBuffer.<init>(Unknown Source)
   java.nio.ByteBuffer.allocateDirect(Unknown Source)
   com.jme.util.geom.BufferUtils.createByteBuffer(Unknown Source)
   com.jmex.audio.util.AudioLoader.read(Unknown Source)
   com.jmex.audio.util.AudioLoader.loadOGG(Unknown Source)
   com.jmex.audio.util.AudioLoader.fillBuffer(Unknown Source)
   com.jmex.audio.openal.OpenALSystem.createAudioTrack(Unknown Source)
   com.jmex.audio.openal.OpenALSystem.createAudioTrack(Unknown Source)
   [...]

java.lang.OutOfMemoryError
   sun.misc.Unsafe.allocateMemory(Native Method)
   java.nio.DirectByteBuffer.<init>(Unknown Source)
   java.nio.ByteBuffer.allocateDirect(Unknown Source)
   com.jme.util.geom.BufferUtils.createByteBuffer(Unknown Source)
   com.jme.util.TextureManager.loadImage(Unknown Source)
   com.jme.util.TextureManager.loadTexture(Unknown Source)
   [...]

Probably the system is out of memory? (not only the vm, if you think 512mb should suffice)

these are bug reports from users out in the field. it appears most of them are running windows xp. here are the machine stats from three of the "OutOfMemoryError" bug reports, selected at random:



Adapter: nv4_disp

DriverVersion: 6.14.10.6085

DisplayVendor: NVIDIA Corporation

DisplayRenderer: GeForce4 MX 4000/AGP/SSE/3DNOW!

DisplayAPIVersion: 1.5.1

java.version: 1.6.0_01

os.name: Windows XP

os.arch: x86



Adapter: ialmrnt5

DriverVersion: 6.14.10.4363

DisplayVendor: Intel

DisplayRenderer: Intel 915G

DisplayAPIVersion: 1.4.0 - Build 4.14.10.4363

java.version: 1.6.0_05

os.name: Windows XP

os.arch: x86



Adapter: nv4_disp

DriverVersion: null

DisplayVendor: NVIDIA Corporation

DisplayRenderer: GeForce2 MX/AGP/SSE2

DisplayAPIVersion: 1.4.0

java.version: 1.6.0_05

os.name: Windows XP

os.arch: x86



anyone see any patterns? i'm trying to find a decent way to poll for the user's installed total RAM (not just the VM memory), but after googling it does not look doable (at least not in a cross platform way)

If you want troubleshooting tips, what OS are you running on?

For some reason, the "systeminfo" command listed in Microsoft's CMD reference is available neither on my 2000 PC nor my XP PCs.  I know of no way to find it with a script.



Interactively, you can do Ctrl-Alt-Delete and bring up the Task Manager.  Besides showing the physical RAM total and available, you can see the memory usage per process.



Keep raising your -Xmx until the problem goes away.  I've found that the OS will not give you enough RAM so that you cause the system to thrash for swap space.  If you get "Could not reserve enough space…" before your OOM exceptions stop, then you need more RAM.



I just wrote a little diagnostic test.  Run it like this:



    java MemTest -Xmx512m 500



to have the process grab up 500M.  Playing with this, you can see how much the OS will allow Java to request with -Xmx.  You can also educate yourself about what error messages the JVM will produce for different kinds of memory failures.



import java.util.List;
import java.util.ArrayList;

public class MemTest {
    static private final String SYNTAX_MSG = "SYNTAX:  java "
        + MemTest.class.getName() + " X    (where X = Megs to load)";
    static public void main(String[] sa) {
        if (sa.length != 1) throw new IllegalArgumentException(SYNTAX_MSG);
        int megs = 0;
        try {
            megs = Integer.parseInt(sa[0]);
        } catch (NumberFormatException nfe) {
            throw new IllegalArgumentException(SYNTAX_MSG);
        }
        List<byte[]> memList = new ArrayList<byte[]>();
        for (int i = 0; i < megs; i++) memList.add(new byte[1024*1024]);
        System.err.println("I'm ok");
        try { Thread.sleep(120000); } catch(InterruptedException ie) {}
    }
}

i would guess its a memory leak and it appears random because the users run the application more or less long.

try to profile your app and see if you somewhere create objects which never get destroyed.

thanks – i'll give both of your suggestions a shot

Hi,



here is a short description of what to do when you're running into an outofmemory:



1. set the VM param "-XX:+HeapDumpOnOutOfMemoryError",

this will cause the VM to create an dump file when running into an OOME.

CAUTION: That can get very big



2. Get the free SAP Memory Analyser Tool from here:

https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/webcontent/uuid/8070021f-5af6-2910-5688-bde8f4fadf31

NOTE: This is also available as Eclipse Plugin if you are interested in that.

Just search for "SAP Memory Analyser Tool".



3. Set your VMs XmX memory setting to the lowest value possible to run fast into

the outofmemory Exception



4. a dump-file should be written in your application's folder



5. Open the dump-file with the SAP Tool



6. What does that Tool for you?

It helps you finding the greatest memory consuming data-structures.

So with that tool you can pretty good find the bottle-necks of your application

without using a profiler (that CAN be a very annoying procedure depending on the

size and complexity of your application).

The first look should be the Dominator View where you can see the most memory

consuming data structures sorted by size.



That document should help you using the tool the first time:

https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/d0eaafd5-6ffd-2910-019c-9007a92b392f



bye,

Maurice

What i forgot to mention:



One can enable that param all the time because it doesn't slow down

your application. In case of debugging purposes i would recommend

enabling the parameter.



If the customer is lucky and don't has generated a multiple gig-sized

dump file, perhaps he could upload it for you to take a look at it  :wink:


  • Maurice

NetBeans 6.0 has a build in profiler. Just right click the project and select "Profile", then select "Memory". You play your game for a while then close it. It shows you which methods create the most objects and then you do your stuff.