From 6460124594f8495374e4a3948f97d14b2b9fa6a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pavel=20=C4=8Cernock=C3=BD?= Date: Mon, 27 Jul 2015 10:26:44 +0200 Subject: [PATCH] CircularBlockingDeque: set removed elements to null to allow garbage collecting them --- .../main/java/org/ros/concurrent/CircularBlockingDeque.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/rosjava/src/main/java/org/ros/concurrent/CircularBlockingDeque.java b/rosjava/src/main/java/org/ros/concurrent/CircularBlockingDeque.java index 20a8f26ef..1e076f5ca 100644 --- a/rosjava/src/main/java/org/ros/concurrent/CircularBlockingDeque.java +++ b/rosjava/src/main/java/org/ros/concurrent/CircularBlockingDeque.java @@ -118,6 +118,7 @@ public T takeFirst() throws InterruptedException { while (true) { if (length > 0) { entry = deque[start]; + deque[start] = null; start = (start + 1) % limit; length--; break; @@ -155,7 +156,9 @@ public T takeLast() throws InterruptedException { synchronized (mutex) { while (true) { if (length > 0) { - entry = deque[(start + length - 1) % limit]; + int idx = (start + length - 1) % limit; + entry = deque[idx]; + deque[idx] = null; length--; break; }