diff options
author | Carsten Weisse <[email protected]> | 2005-05-17 17:20:31 +0000 |
---|---|---|
committer | Carsten Weisse <[email protected]> | 2005-05-17 17:20:31 +0000 |
commit | c003a7569723338b7339f34b37fba17028e0144d (patch) | |
tree | 961492f425b26d4814d90729b2bff7bbb440c34b /test/jake2 | |
parent | e3562339a02625667fa75b6074469b4d7ef80232 (diff) |
simple test to see what happens with direct buffers (garbage collected?).
use "top" on linux or "Task Manager" on Win32. The answer is yes.
Diffstat (limited to 'test/jake2')
-rw-r--r-- | test/jake2/render/DisposeBuffer.java | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/test/jake2/render/DisposeBuffer.java b/test/jake2/render/DisposeBuffer.java new file mode 100644 index 0000000..d17157c --- /dev/null +++ b/test/jake2/render/DisposeBuffer.java @@ -0,0 +1,45 @@ +/* + * 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) { + } + } +} |