From: Simon Delisle Date: Wed, 14 Aug 2013 18:35:31 +0000 (-0400) Subject: Ctf: add removeIterator() to prevent OutOfMemory exception (Bug 414998) X-Git-Url: http://git.efficios.com/?a=commitdiff_plain;h=f0414df8b561a270603492d4d6ebe6e195dd9cbc;p=deliverable%2Ftracecompass.git Ctf: add removeIterator() to prevent OutOfMemory exception (Bug 414998) Change-Id: I0a42a1b4d7eb14b37bc97471dba1b4aae44d2f4c Signed-off-by: Simon Delisle Reviewed-on: https://git.eclipse.org/r/15487 Reviewed-by: Alexandre Montplaisir IP-Clean: Alexandre Montplaisir Tested-by: Alexandre Montplaisir --- diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfIteratorManager.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfIteratorManager.java index 2d85af8368..65fac21e59 100644 --- a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfIteratorManager.java +++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfIteratorManager.java @@ -6,7 +6,9 @@ * accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * - * Contributors: Matthew Khouzam - Initial API and implementation + * Contributors: + * Matthew Khouzam - Initial API and implementation + * Simon Delisle - Added a method to remove the iterator *******************************************************************************/ package org.eclipse.linuxtools.tmf.core.ctfadaptor; @@ -71,6 +73,22 @@ public abstract class CtfIteratorManager { final CtfTmfContext ctx) { return map.get(trace).getIterator(ctx); } + + /** + * Remove an iterator for a given trace and context + * + * @param trace + * the trace + * @param ctx + * the context + * @since 2.1 + */ + public static synchronized void removeIterator(final CtfTmfTrace trace, final CtfTmfContext ctx) { + CtfTraceManager traceManager = map.get(trace); + if (traceManager != null) { + traceManager.removeIterator(ctx); + } + } } /** @@ -154,6 +172,11 @@ class CtfTraceManager { return retVal; } + public void removeIterator(CtfTmfContext context) { + fMap.remove(context); + fRandomAccess.remove(context); + } + /** * Add a pair of context and element to the hashmap and the arraylist. * diff --git a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfTmfContext.java b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfTmfContext.java index b1ef6d7955..df2076b5e1 100644 --- a/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfTmfContext.java +++ b/org.eclipse.linuxtools.tmf.core/src/org/eclipse/linuxtools/tmf/core/ctfadaptor/CtfTmfContext.java @@ -6,7 +6,9 @@ * accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * - * Contributors: Matthew Khouzam - Initial API and implementation + * Contributors: + * Matthew Khouzam - Initial API and implementation + * Simon Delisle - Remove the iterator in dispose() *******************************************************************************/ package org.eclipse.linuxtools.tmf.core.ctfadaptor; @@ -137,7 +139,7 @@ public class CtfTmfContext implements ITmfContext { @Override public void dispose() { - // do nothing + CtfIteratorManager.removeIterator(fTrace, this); } /**