Android memory allocation

Of course… that’s waaaaay better.

I don’t know what your tacho looks like but there are ways to do it where the update would even be super minimal.

there is a final picture for the background, which gets set its image load at first start, And for the needle it is a png with a 2px line. This picture I load every update because i rotate it by the current speed and I am way too lazy to calculate the delta rotation the soeed value is an int and I now update it when the current speed is different to the speed at the last update or when the display width is changing. I just tried it in combination with a 256 * 256 Terrain Quad and the Android Studio Performance Manager shows a relatively stable memusage of 130 MB for the AVD, while running the app.

Just curious, why would you need to calculate delta rotation instead of just setting the absolute rotation?

Just curious, why would you need to calculate delta rotation instead of just setting the absolute rotation?

Have I rotate an identity matrix and set it as rotation to the picture, or how did this work?

Quaternion q = new Quaternion().fromAngles(0, 0, radiansAroundZ);
mySpatial.setLocalRotation(q);

Hi! sorry for rebumping this thread but I think could be usefull for more users.

I had a similar issue running my game on android because y default it allows you really low direct memory. I fixed this by overriding NIO max memory by reflection as follows:

    try
    {
        Class c = Class.forName("java.nio.Bits");
        Field maxMemory;
        try
        {
            maxMemory = c.getDeclaredField("maxMemory"); // java < 11 
        }
        catch(NoSuchFieldException ex)
        {
            maxMemory = c.getDeclaredField("MAX_MEMORY"); // java >= 11
        }
        maxMemory.setAccessible(true);
        Field reservedMemory = c.getDeclaredField("reservedMemory");
        reservedMemory.setAccessible(true);
        synchronized (c) {
            maxMemory.setLong(null, 1610612736L);
            Long maxMemoryValue = (Long)maxMemory.get(null);
            Long reservedMemoryValueLong=0L;
            if(reservedMemory.get(null) instanceof java.util.concurrent.atomic.AtomicLong)
            {
                java.util.concurrent.atomic.AtomicLong reservedMemoryValue = (java.util.concurrent.atomic.AtomicLong)reservedMemory.get(null);
                reservedMemoryValueLong=reservedMemoryValue.longValue();
            }
            else
            {
                reservedMemoryValueLong=(Long)reservedMemory.get(null);
            }
            
            System.out.println("Memory: " + reservedMemoryValueLong + " / " + maxMemoryValue );
        }
    } catch (ClassNotFoundException ex) {
        Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
    } catch (NoSuchFieldException ex) {
        Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
    } catch (SecurityException ex) {
        Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IllegalArgumentException ex) {
        Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
    } catch (IllegalAccessException ex) {
        Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
    }

I’m using the same code for both desktop and android and I’ve not faced any more OOM issues. Please note it’s a really high number (1610612736L) tune it according to your needs

3 Likes

Cool.