[541539] Simple batch mode comparison of two snapshots
Snapshots from a factory should be disposed via the factory.
Change-Id: I1ff9f4b80a44b7804b886d9d15ba0435fae73333
diff --git a/plugins/org.eclipse.mat.api/src/org/eclipse/mat/inspections/DeltaHistogram.java b/plugins/org.eclipse.mat.api/src/org/eclipse/mat/inspections/DeltaHistogram.java
index 224bf32..87223e5 100644
--- a/plugins/org.eclipse.mat.api/src/org/eclipse/mat/inspections/DeltaHistogram.java
+++ b/plugins/org.eclipse.mat.api/src/org/eclipse/mat/inspections/DeltaHistogram.java
@@ -19,6 +19,7 @@
import org.eclipse.mat.query.annotations.Argument.Advice;
import org.eclipse.mat.snapshot.Histogram;
import org.eclipse.mat.snapshot.ISnapshot;
+import org.eclipse.mat.snapshot.SnapshotFactory;
import org.eclipse.mat.util.IProgressListener;
import org.eclipse.mat.util.SimpleMonitor;
@@ -39,6 +40,8 @@
Histogram h2 = (Histogram) super.execute(sm.nextMonitor());
sm.nextMonitor();
Histogram h3 = h2.diffWithBaseline(h1);
+ // Currently it seems a SECONDARY_SNAPSHOT is not disposed by the caller.
+ SnapshotFactory.dispose(snapshot2);
listener.done();
return h3;
}
diff --git a/plugins/org.eclipse.mat.api/src/org/eclipse/mat/snapshot/SnapshotFactory.java b/plugins/org.eclipse.mat.api/src/org/eclipse/mat/snapshot/SnapshotFactory.java
index 12d5d87..1620f51 100644
--- a/plugins/org.eclipse.mat.api/src/org/eclipse/mat/snapshot/SnapshotFactory.java
+++ b/plugins/org.eclipse.mat.api/src/org/eclipse/mat/snapshot/SnapshotFactory.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008, 2010 SAP AG and IBM Corporation.
+ * Copyright (c) 2008, 2018 SAP AG and IBM Corporation.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -55,6 +55,8 @@
/**
* Free resources when the snapshot is no longer needed.
+ * Use instead of {@link ISnapshot#dispose()} if the snapshot is obtained from {@link #openSnapshot(File, Map, IProgressListener)}
+ * as openSnapshot() may obtain a copy from a cache.
* @param snapshot
*/
void dispose(ISnapshot snapshot);
@@ -153,6 +155,8 @@
* main memory, file and socket handles...) when the last user has disposed
* it through the snapshot factory. After calling this method the snapshot
* can't be used anymore.
+ * Use instead of {@link ISnapshot#dispose()} if the snapshot is obtained from {@link #openSnapshot(File, Map, IProgressListener)}
+ * as openSnapshot() may obtain a copy from a cache.
*
* @param snapshot
* snapshot which should be disposed
diff --git a/plugins/org.eclipse.mat.tests/src/org/eclipse/mat/tests/acquire/AcquireDumpTest.java b/plugins/org.eclipse.mat.tests/src/org/eclipse/mat/tests/acquire/AcquireDumpTest.java
index 17ad4f7..eb9ff27 100644
--- a/plugins/org.eclipse.mat.tests/src/org/eclipse/mat/tests/acquire/AcquireDumpTest.java
+++ b/plugins/org.eclipse.mat.tests/src/org/eclipse/mat/tests/acquire/AcquireDumpTest.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2015,2017 IBM Corporation.
+ * Copyright (c) 2015, 2018 IBM Corporation.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -154,7 +154,7 @@
}
finally
{
- answer.dispose();
+ SnapshotFactory.dispose(answer);
}
}
finally
diff --git a/plugins/org.eclipse.mat.tests/src/org/eclipse/mat/tests/snapshot/QueriesTest.java b/plugins/org.eclipse.mat.tests/src/org/eclipse/mat/tests/snapshot/QueriesTest.java
index 5be8965..076b850 100644
--- a/plugins/org.eclipse.mat.tests/src/org/eclipse/mat/tests/snapshot/QueriesTest.java
+++ b/plugins/org.eclipse.mat.tests/src/org/eclipse/mat/tests/snapshot/QueriesTest.java
@@ -897,7 +897,7 @@
assertNotNull(t);
ISnapshot newSnapshot = SnapshotFactory.openSnapshot(fn, Collections.<String,String>emptyMap(), new VoidProgressListener());
assertNotNull(newSnapshot);
- newSnapshot.dispose();
+ SnapshotFactory.dispose(newSnapshot);
}
finally
{
@@ -954,7 +954,7 @@
ISnapshot newSnapshot = SnapshotFactory.openSnapshot(fn, Collections.<String, String> emptyMap(),
new VoidProgressListener());
assertNotNull(newSnapshot);
- newSnapshot.dispose();
+ SnapshotFactory.dispose(newSnapshot);
}
finally
{