aboutsummaryrefslogtreecommitdiffstats
path: root/test/jake2/render/DisposeBuffer.java
blob: d17157c8bf6fea2f865a97f4cc426240b0c88197 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
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) {
        }
    }
}