From 1ee803fcc881bd899ee5faf57f765668308f2c67 Mon Sep 17 00:00:00 2001 From: Alena Laskavaia Date: Mon, 18 Oct 2010 01:01:53 +0000 Subject: [PATCH] Bug 327779 - fixed cash items leakage --- .../core/cxx/model/AbstractIndexAstChecker.java | 1 + .../cdt/codan/core/cxx/model/CxxModelsCache.java | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/codan/org.eclipse.cdt.codan.core.cxx/src/org/eclipse/cdt/codan/core/cxx/model/AbstractIndexAstChecker.java b/codan/org.eclipse.cdt.codan.core.cxx/src/org/eclipse/cdt/codan/core/cxx/model/AbstractIndexAstChecker.java index d96f8401b57..ca28daa251a 100644 --- a/codan/org.eclipse.cdt.codan.core.cxx/src/org/eclipse/cdt/codan/core/cxx/model/AbstractIndexAstChecker.java +++ b/codan/org.eclipse.cdt.codan.core.cxx/src/org/eclipse/cdt/codan/core/cxx/model/AbstractIndexAstChecker.java @@ -121,6 +121,7 @@ public abstract class AbstractIndexAstChecker extends AbstractCheckerWithProblem @SuppressWarnings("restriction") public synchronized void processModel(Object model) { if (model instanceof IASTTranslationUnit) { + CxxModelsCache.getInstance().clearCash(); IASTTranslationUnit ast = (IASTTranslationUnit) model; IPath location = new Path(ast.getFilePath()); IFile astFile = ResourceLookup.selectFileForLocation(location, diff --git a/codan/org.eclipse.cdt.codan.core.cxx/src/org/eclipse/cdt/codan/core/cxx/model/CxxModelsCache.java b/codan/org.eclipse.cdt.codan.core.cxx/src/org/eclipse/cdt/codan/core/cxx/model/CxxModelsCache.java index cd00145732f..028d8b31167 100644 --- a/codan/org.eclipse.cdt.codan.core.cxx/src/org/eclipse/cdt/codan/core/cxx/model/CxxModelsCache.java +++ b/codan/org.eclipse.cdt.codan.core.cxx/src/org/eclipse/cdt/codan/core/cxx/model/CxxModelsCache.java @@ -44,6 +44,9 @@ public class CxxModelsCache { IControlFlowGraph cfg = cfgmap.get(func); if (cfg!=null) return cfg; cfg = CxxControlFlowGraph.build(func); + if (cfgmap.size()>20) { // if too many function better drop the cash XXX should be LRU + cfgmap.clear(); + } cfgmap.put(func, cfg); return cfg; } @@ -53,11 +56,11 @@ public class CxxModelsCache { return ast; } - cfgmap.clear(); // create translation unit and access index ICElement celement = CoreModel.getDefault().create(file); if (!(celement instanceof ITranslationUnit)) return null; // not a C/C++ file + clearCash(); this.file = file; //System.err.println("Making ast for "+file); tu = (ITranslationUnit) celement; @@ -75,6 +78,16 @@ public class CxxModelsCache { } } + /** + * Clear cash for current file + */ + public void clearCash() { + cfgmap.clear(); + ast = null; + tu = null; + index = null; + } + public synchronized IIndex getIndex(IFile file) throws CoreException, InterruptedException { if (file.equals(this.file)) {