JVM-independent solution to flushing memory

原创 2004年10月05日 02:30:00

http://www.onjava.com/pub/a/onjava/2001/08/22/optimization.html<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Ideally, the JVM would provide a method that would flush memory for me. System.gc() looks like it should be such a call. Unfortunately, System.gc() is only a hint to the JVM that "now would be a good time to run the garbage collector." The JVM can ignore the hint, or can run a partial garbage collection, or a full mark-and-sweep of all spaces, or whatever. Instead of relying on the garbage collector, I adapt the method from the previous section to flush memory. I do this by allocating as much memory as possible, as with the earlier testMemory() method, and then I release all held memory and request a little more. The last request is to trigger the garbage collector to immediately reclaim all the memory I was holding onto. The method is straightforward:

This is a JVM-independent solution to flushing memory. You could even conceivably use this in an application if you knew that you had several seconds of time at some point when the application could be doing nothing else, but I wouldn't really recommend it. Although flushMemory() should work on any JVM, it is a stressful procedure and may break some JVMs. In particular I know that the Windows JVM from the Sun 1.2.0 release crashed the main thread when I ran flushMemory(), and put the garbage collector thread into a loop if I additionally ran with the -verbosegc option.

Operating system paging occurs when a program is too big to fit into available real memory (RAM), but can fit in virtual memory. Paging moves pages of the program back and forth between the RAM and the paging file on disk, allowing the operating system to seem like it has a larger memory than the available RAM, but at the expense of program performance.



  • u013494310
  • u013494310
  • 2015年04月02日 15:31
  • 3106

Flushing and Cleaning Cache Memory

ARM uses the terms flush and clean to describe two basic operations performed on acache.To “flush a ...
  • better_yin
  • better_yin
  • 2010年09月09日 18:36
  • 169

save the transient instance before flushing

 三张数据表的关系如下图  在java中如下写法报错(错误信息:save the transient instance before flushing):  @OneToMany...
  • DaiDaiLiu
  • DaiDaiLiu
  • 2015年03月25日 18:37
  • 3986

Hibernate常见错误之save the transient instance before flushing

Hibernate中错误org.hibernate.TransientObjectException: object references an unsaved transient instance ...
  • weixin_38278878
  • weixin_38278878
  • 2017年07月30日 20:46
  • 803

服务器端包含 java.lang.IllegalStateException: Exception occurred when flushing

org.apache.jasper.JasperException: java.lang.IllegalStateException: Exception occurred when flushing...
  • tanyit
  • tanyit
  • 2012年03月03日 22:33
  • 6351

HDU2719:The Seven Percent Solution

Problem Description Uniform Resource Identifiers (or URIs) are strings like http://icpc.baylor.edu/...
  • libin56842
  • libin56842
  • 2013年04月17日 22:04
  • 1739

save the transient instance before flushing错误解决办法

近日在项目中遇到以下错误,着实郁闷了一把:    org.hibernate.TransientObjectException: object references an unsaved transi...
  • leadergg
  • leadergg
  • 2008年12月31日 16:26
  • 32884


Servlet.service() for servlet [action] in context with path [/s] threw exception [java.lang.IllegalS...
  • ht1456749
  • ht1456749
  • 2014年10月06日 15:20
  • 619


HRegion中,有两个关于关闭的状态标志位成员变量,分别定义如下: final AtomicBoolean closed = new AtomicBoolean(false); final Atom...
  • lipeng_bigdata
  • lipeng_bigdata
  • 2016年02月25日 21:21
  • 3684

Flushing out pdflush

转自:http://lwn.net/Articles/326552/   The kernel page cache contains in-memory copies of data block...
  • njuitjf
  • njuitjf
  • 2015年01月06日 14:42
  • 1609
您举报文章:JVM-independent solution to flushing memory