Revision: 484
Author: dbrosius
Date: 2006-04-18 17:46:38 -0700 (Tue, 18 Apr 2006)
ViewCVS: http://svn.sourceforge.net/fb-contrib/?rev=484&view=rev
Log Message:
-----------
Manually cleanup memory now that StatelessDetector is removed.
Modified Paths:
--------------
trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/PossibleMemoryBloat.java
Modified: trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/PossibleMemoryBloat.java
===================================================================
--- trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/PossibleMemoryBloat.java 2006-04-19 00:44:32 UTC (rev 483)
+++ trunk/fb-contrib/src/com/mebigfatguy/fbcontrib/detect/PossibleMemoryBloat.java 2006-04-19 00:46:38 UTC (rev 484)
@@ -35,7 +35,6 @@
import edu.umd.cs.findbugs.FieldAnnotation;
import edu.umd.cs.findbugs.OpcodeStack;
import edu.umd.cs.findbugs.SourceLineAnnotation;
-import edu.umd.cs.findbugs.StatelessDetector;
import edu.umd.cs.findbugs.ba.ClassContext;
/**
@@ -44,7 +43,8 @@
* Such class fields are likely causes of memory bloat.
*
*/
-public class PossibleMemoryBloat extends BytecodeScanningDetector implements StatelessDetector {
+public class PossibleMemoryBloat extends BytecodeScanningDetector
+{
private static final Set<String> bloatableSigs = new HashSet<String>();
static {
bloatableSigs.add("Ljava/util/ArrayList;");
@@ -93,8 +93,8 @@
increasingMethods.add("put");
}
private BugReporter bugReporter;
- private Map<FieldAnnotation, SourceLineAnnotation> bloatableFields = new HashMap<FieldAnnotation, SourceLineAnnotation>();
- private OpcodeStack stack = new OpcodeStack();
+ private Map<FieldAnnotation, SourceLineAnnotation> bloatableFields;
+ private OpcodeStack stack;
private String methodName;
/**
@@ -106,16 +106,6 @@
}
/**
- * clone this detector so that it can be a StatelessDetector
- *
- * @return a clone of this object
- */
- @Override
- public Object clone() throws CloneNotSupportedException {
- return super.clone();
- }
-
- /**
* collects static fields that are likely bloatable objects and if found
* allows the visitor to proceed, at the end report all leftover fields
*
@@ -123,30 +113,36 @@
*/
@Override
public void visitClassContext(ClassContext classContext) {
- bloatableFields.clear();
- JavaClass cls = classContext.getJavaClass();
- Field[] fields = cls.getFields();
- for (Field f : fields) {
- if (f.isStatic()) {
- String sig = f.getSignature();
- if (bloatableSigs.contains(sig)) {
- bloatableFields.put(FieldAnnotation.fromBCELField(cls.getClassName(), f), null);
+ try {
+ bloatableFields = new HashMap<FieldAnnotation, SourceLineAnnotation>();
+ JavaClass cls = classContext.getJavaClass();
+ Field[] fields = cls.getFields();
+ for (Field f : fields) {
+ if (f.isStatic()) {
+ String sig = f.getSignature();
+ if (bloatableSigs.contains(sig)) {
+ bloatableFields.put(FieldAnnotation.fromBCELField(cls.getClassName(), f), null);
+ }
}
}
- }
-
- if (bloatableFields.size() > 0) {
- super.visitClassContext(classContext);
-
- for (Map.Entry<FieldAnnotation, SourceLineAnnotation> entry : bloatableFields.entrySet()) {
- SourceLineAnnotation sla = entry.getValue();
- if (sla != null) {
- bugReporter.reportBug(new BugInstance(this, "PMB_POSSIBLE_MEMORY_BLOAT", NORMAL_PRIORITY)
- .addClass(this)
- .addSourceLine(sla)
- .addField(entry.getKey()));
+
+ if (bloatableFields.size() > 0) {
+ stack = new OpcodeStack();
+ super.visitClassContext(classContext);
+
+ for (Map.Entry<FieldAnnotation, SourceLineAnnotation> entry : bloatableFields.entrySet()) {
+ SourceLineAnnotation sla = entry.getValue();
+ if (sla != null) {
+ bugReporter.reportBug(new BugInstance(this, "PMB_POSSIBLE_MEMORY_BLOAT", NORMAL_PRIORITY)
+ .addClass(this)
+ .addSourceLine(sla)
+ .addField(entry.getKey()));
+ }
}
}
+ } finally {
+ stack = null;
+ bloatableFields = null;
}
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|