我怎样才能知道运行时程序使用内存的情况呢??????????????????

yangjing0420 2003-10-19 12:20:58
问题同上。谢谢先!
...全文
100 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
yangjing0420 2003-10-20
  • 打赏
  • 举报
回复
谢谢
flagfly 2003-10-20
  • 打赏
  • 举报
回复
mark
moke33 2003-10-19
  • 打赏
  • 举报
回复
查了api,找不到,关注
bb_star_bb 2003-10-19
  • 打赏
  • 举报
回复
好像是经过RuntimeObject来得到的。。。
ludf 2003-10-19
  • 打赏
  • 举报
回复
其实有些书上都讲过了,多看写书吧!

通过类java.lang.Runtime的方法totoalMemory()和freeMemory()可以分别获取虚拟机的总存储容量和剩余存储容量,总存储容量依赖于虚拟机运行的环境,可能随着时间变化而不同。方法gc()用来调用垃圾收集功能,运行垃圾收集会增大freeMemory()返回的值。例如:

import javax.microedition.midlet.*;
public class ShowMemory extends MIDlet {
public void startApp() throws MIDletStateChangeException {
Runtime runtime = Runtime.getRuntime();
System.out.println("Total Memory:" + runtime.totalMemory());
System.out.println("Free Memory:" + runtime.freeMemory());
runtime.gc();
System.out.println("After gc(),Free Memory:"+runtime.freeMemory());
}
public void pauseApp() {}
public void destroyApp(boolean unconditioanl) {}
}

good luck
moke33 2003-10-19
  • 打赏
  • 举报
回复
totalMemory

public long totalMemory()

Returns the total amount of memory in the Java Virtual Machine. The value returned by this method may vary over time, depending on the host environment.
Note that the amount of memory required to hold an object of any given type may be implementation-dependent.

Returns:
the total amount of memory currently available for current and future objects, measured in bytes.
moke33 2003-10-19
  • 打赏
  • 举报
回复
freeMemory

public long freeMemory()

Returns the amount of free memory in the system. Calling the gc method may result in increasing the value returned by freeMemory.
Returns:
an approximation to the total amount of memory currently available for future allocated objects, measured in bytes.

13,100

社区成员

发帖
与我相关
我的任务
社区描述
Java J2ME
社区管理员
  • J2ME社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧