| 56 | |
| 57 | Thread referenceThread = new Thread() { |
| 58 | public void run() { |
| 59 | while (true) { |
| 60 | try { |
| 61 | PhantomReference ref = (PhantomReference) referenceQueue.remove(); |
| 62 | |
| 63 | LOG.info(String.format("GC removing %s (%s) from memory", ref.getClass().getName(), ref.hashCode())); |
| 64 | |
| 65 | ref.cleanup(); |
| 66 | phantomReferences.remove(ref); |
| 67 | } catch (Exception ex) { |
| 68 | // log exception, continue |
| 69 | LOG.error("Error while cleaning up reference queue", ex); |
| 70 | } |
| 71 | } |
| 72 | } |
| 73 | }; |
| 74 | referenceThread.setDaemon(true); |
| 75 | referenceThread.start(); |