set Minimum Heap Size - Android Android OS

Android examples for Android OS:Heap

Description

set Minimum Heap Size

Demo Code


//package com.java2s;
import java.lang.reflect.Method;

public class Main {
    public static void setMinimumHeapSize(long size) {
        try {//  ww w .j a  v a2 s.  c o m
            Class VMRuntimeClass = Class.forName("dalvik.system.VMRuntime");
            Method getRuntimeMethod = VMRuntimeClass.getMethod(
                    "getRuntime", new Class[0]);
            Class[] arrayOfClass = new Class[1];
            arrayOfClass[0] = Long.TYPE;
            Method setMinimumHeapSizeMethod = VMRuntimeClass.getMethod(
                    "setMinimumHeapSize", arrayOfClass);
            Object runtimeObject = getRuntimeMethod.invoke(null,
                    new Object[0]);
            Object[] arrayOfObject = new Object[1];
            arrayOfObject[0] = Long.valueOf(size);
            setMinimumHeapSizeMethod.invoke(runtimeObject, arrayOfObject);
        } catch (Throwable localThrowable) {
            localThrowable.printStackTrace();
        }
    }
}

Related Tutorials