From: Carsten W. <ca...@us...> - 2005-05-17 17:20:40
|
Update of /cvsroot/jake2/jake2/test/jake2/render In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5642/test/jake2/render Added Files: DisposeBuffer.java Log Message: simple test to see what happens with direct buffers (garbage collected?). use "top" on linux or "Task Manager" on Win32. The answer is yes. --- NEW FILE: DisposeBuffer.java --- /* * Created on May 13, 2005 * */ package jake2.render; import java.nio.Buffer; import java.nio.ByteBuffer; /** * @author cwei * */ public class DisposeBuffer { // 160 MB direct buffers static int SIZE = 1024 * 1024; static int COUNT = 160; public static void main(String[] args) { System.out.println("DirectBuffer allocation."); Buffer[] buf = new Buffer[COUNT]; Runtime run = Runtime.getRuntime(); System.gc(); for (int i = 0; i < COUNT; i++) { buf[i] = ByteBuffer.allocateDirect(SIZE); } System.gc(); System.out.println((run.totalMemory() / 1024) + "KB heap"); try { Thread.sleep(10000); } catch (InterruptedException e) { } System.out.println("DirectBuffer dispose."); for (int i = 0; i < COUNT; i++) { buf[i] = null; } System.gc(); System.out.println((run.totalMemory() / 1024) + "KB heap"); try { Thread.sleep(20000); } catch (InterruptedException e) { } } } |