1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-24 01:15:29 +02:00

Bug 327779 - fixed cash items leakage

This commit is contained in:
Alena Laskavaia 2010-10-18 01:01:53 +00:00
parent 7b7b5e2d0e
commit 1ee803fcc8
2 changed files with 15 additions and 1 deletions

View file

@ -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,

View file

@ -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)) {