mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-05 15:25:49 +02:00
Bug 327779 - fixed cash items leakage
This commit is contained in:
parent
7b7b5e2d0e
commit
1ee803fcc8
2 changed files with 15 additions and 1 deletions
|
@ -121,6 +121,7 @@ public abstract class AbstractIndexAstChecker extends AbstractCheckerWithProblem
|
||||||
@SuppressWarnings("restriction")
|
@SuppressWarnings("restriction")
|
||||||
public synchronized void processModel(Object model) {
|
public synchronized void processModel(Object model) {
|
||||||
if (model instanceof IASTTranslationUnit) {
|
if (model instanceof IASTTranslationUnit) {
|
||||||
|
CxxModelsCache.getInstance().clearCash();
|
||||||
IASTTranslationUnit ast = (IASTTranslationUnit) model;
|
IASTTranslationUnit ast = (IASTTranslationUnit) model;
|
||||||
IPath location = new Path(ast.getFilePath());
|
IPath location = new Path(ast.getFilePath());
|
||||||
IFile astFile = ResourceLookup.selectFileForLocation(location,
|
IFile astFile = ResourceLookup.selectFileForLocation(location,
|
||||||
|
|
|
@ -44,6 +44,9 @@ public class CxxModelsCache {
|
||||||
IControlFlowGraph cfg = cfgmap.get(func);
|
IControlFlowGraph cfg = cfgmap.get(func);
|
||||||
if (cfg!=null) return cfg;
|
if (cfg!=null) return cfg;
|
||||||
cfg = CxxControlFlowGraph.build(func);
|
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);
|
cfgmap.put(func, cfg);
|
||||||
return cfg;
|
return cfg;
|
||||||
}
|
}
|
||||||
|
@ -53,11 +56,11 @@ public class CxxModelsCache {
|
||||||
return ast;
|
return ast;
|
||||||
}
|
}
|
||||||
|
|
||||||
cfgmap.clear();
|
|
||||||
// create translation unit and access index
|
// create translation unit and access index
|
||||||
ICElement celement = CoreModel.getDefault().create(file);
|
ICElement celement = CoreModel.getDefault().create(file);
|
||||||
if (!(celement instanceof ITranslationUnit))
|
if (!(celement instanceof ITranslationUnit))
|
||||||
return null; // not a C/C++ file
|
return null; // not a C/C++ file
|
||||||
|
clearCash();
|
||||||
this.file = file;
|
this.file = file;
|
||||||
//System.err.println("Making ast for "+file);
|
//System.err.println("Making ast for "+file);
|
||||||
tu = (ITranslationUnit) celement;
|
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)
|
public synchronized IIndex getIndex(IFile file)
|
||||||
throws CoreException, InterruptedException {
|
throws CoreException, InterruptedException {
|
||||||
if (file.equals(this.file)) {
|
if (file.equals(this.file)) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue