Can't figure out memory usage

I’ve copypasted this Monitor direct memory usage in your app…

Then I wrote this code:

            System.out.println("Usage:     "+MemoryUtils.getDirectMemoryUsage());
            System.out.println("Total cap: "+MemoryUtils.getDirectMemoryTotalCapacity());
            logoM.setTexture("ColorMap", app.getAssetManager().loadTexture("Models/8Ktexture.png"));
            System.out.println("Usage:     "+MemoryUtils.getDirectMemoryUsage());
            System.out.println("Total cap: "+MemoryUtils.getDirectMemoryTotalCapacity());

I get this result:

Usage: 227643264
Total cap: 227643180
Usage: 424245520
Total cap: 424245460

Can’t figure out the meaning… why is Total capacity increasing? Also, why usage is increased by 200Mb when I’m loading a 8096x8096 texture? I would expect 1Gb instead…

I guess because it grows as needed up to the max specified on the command line.

Your math seems off.
8096x8096x4 = 262,180,864

…or 200 MB.

Then where is different from memory usage? I know this is Java and not JME, but still wondering…

Ops! You’re right. However, my memory usage incremented by 196,602,256, and not by 262,180,864.

So there’s still 65,578,608 missing…

Java requests memory from the OS in large chunks and then gives it out to the app in smaller chunks.

Well, one of two things happened:

  1. magic gremlins are adding magic compression in your computer.

  2. something else was freed at the same time to make room for it so you didn’t see an accurate increase.

…I know where my money is going.

Whatever you are trying to do… there is no sure fire accurate way to do it. You could call System.gc() four or five times before loading the texture if you really wanted the best possibility of seeing memory grow accurately but it still might not.

One thing is sure, there is no magic memory wormhole in your system so it’s got to be a sensor issue.

1 Like