@@ -55,6 +55,7 @@ final class ProfilerSnapshotNPS extends ProfilerSnapshot {
5555
5656 private static final Logger LOGGER = Logger .getLogger (ProfilerSnapshotNPS .class .getName ());
5757 private LoadedSnapshot loadedSnapshot ;
58+ private FileObject snapshotFO ;
5859 private TopComponent srw ;
5960
6061 ProfilerSnapshotNPS () {
@@ -63,26 +64,26 @@ final class ProfilerSnapshotNPS extends ProfilerSnapshot {
6364
6465 ProfilerSnapshotNPS (File snapshot , DataSource master ) {
6566 super (snapshot , master );
66- FileObject fobj = FileUtil .toFileObject (FileUtil .normalizeFile (snapshot ));
67- loadedSnapshot = ResultsManager .getDefault ().loadSnapshot (fobj );
67+ snapshotFO = FileUtil .toFileObject (FileUtil .normalizeFile (snapshot ));
6868 }
6969
7070 @ Override
71- public LoadedSnapshot getLoadedSnapshot () {
71+ public synchronized LoadedSnapshot getLoadedSnapshot () {
72+ if (loadedSnapshot == null )
73+ loadedSnapshot = ResultsManager .getDefault ().loadSnapshot (snapshotFO );
7274 return loadedSnapshot ;
7375 }
7476
7577 @ Override
7678 protected void remove () {
7779 super .remove ();
78- ResultsManager .getDefault ().closeSnapshot (loadedSnapshot );
79-
80+ closeSnapshot ();
8081 }
8182
8283 @ Override
8384 protected Image resolveIcon () {
8485 try {
85- int snapshotType = getLoadedSnapshot ().getType ( );
86+ int snapshotType = ResultsManager . getDefault ().getSnapshotType ( snapshotFO );
8687 switch (snapshotType ) {
8788 case LoadedSnapshot .SNAPSHOT_TYPE_CPU :
8889 return ImageUtilities .mergeImages (CPU_ICON , NODE_BADGE , 0 , 0 );
@@ -106,7 +107,7 @@ protected Image resolveIcon() {
106107 @ Override
107108 JComponent getUIComponent () {
108109 if (srw == null ) {
109- srw = SnapshotResultsWindow .get (loadedSnapshot , CommonConstants .SORTING_COLUMN_DEFAULT , false );
110+ srw = SnapshotResultsWindow .get (getLoadedSnapshot () , CommonConstants .SORTING_COLUMN_DEFAULT , false );
110111 srw .setPreferredSize (new Dimension (1 , 1 ));
111112
112113 DataSource master = getMaster ();
@@ -150,4 +151,9 @@ public void run() {
150151 });
151152 }
152153 }
154+
155+ private synchronized void closeSnapshot () {
156+ ResultsManager .getDefault ().closeSnapshot (loadedSnapshot );
157+ loadedSnapshot = null ;
158+ }
153159}
0 commit comments