2
由於堆大小的限制,我的Midlet需要以不同的堆大小以不同的方式運行。例如,它應該加載更多或更少的位圖字體。如何在j2me中通過手機獲取最大可用堆大小?
由於堆大小的限制,我的Midlet需要以不同的堆大小以不同的方式運行。例如,它應該加載更多或更少的位圖字體。如何在j2me中通過手機獲取最大可用堆大小?
// Get current size of heap in bytes
long heapSize = Runtime.getRuntime().totalMemory();
// Get maximum size of heap in bytes. The heap cannot grow beyond this size.
// Any attempt will result in an OutOfMemoryException.
long heapMaxSize = Runtime.getRuntime().maxMemory();
// Get amount of free memory within the heap in bytes. This size will increase
// after garbage collection and decrease as new objects are created.
long heapFreeSize = Runtime.getRuntime().freeMemory();
maxMemory法中缺少CLDC 1.1,但一個有效的答案反正。 – Trax