| 33 | |
| 34 | public class CanonicalMapping { |
| 35 | public static void main(String[] args) { |
| 36 | int size = 1000; |
| 37 | // Or, choose size via the command line: |
| 38 | if(args.length > 0) |
| 39 | size = Integer.valueOf(args[0]); |
| 40 | Key[] keys = new Key[size]; |
| 41 | WeakHashMap<Key,Value> map = |
| 42 | new WeakHashMap<>(); |
| 43 | for(int i = 0; i < size; i++) { |
| 44 | Key k = new Key(Integer.toString(i)); |
| 45 | Value v = new Value(Integer.toString(i)); |
| 46 | if(i % 3 == 0) |
| 47 | keys[i] = k; // Save as "real" references |
| 48 | map.put(k, v); |
| 49 | } |
| 50 | System.gc(); |
| 51 | } |
| 52 | } |