Bug 39999 - LastEditPostion temporarily "leaks" one Document
Summary: LastEditPostion temporarily "leaks" one Document
Status: RESOLVED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: Text (show other bugs)
Version: 3.0   Edit
Hardware: PC Windows 2000
: P3 normal (vote)
Target Milestone: 3.1 M3   Edit
Assignee: Platform-Text-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2003-07-14 00:32 EDT by David Williams CLA
Modified: 2004-09-24 11:24 EDT (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description David Williams CLA 2003-07-14 00:32:45 EDT
Not a growing leak, but after editor is closed, the TextEditorPlugin still has 
the LastEditPosition, which has a Selection instance, which has the Document 
instance. Depending on what the Document is holding on to, this can leave a lot 
in memory unnecessarily. 

One fix is to simply call during dispose
    TextEditorPlugin.getDefault().setLastEditPosition(null);
if in fact the editor set it (it appears all users of getLastEditPosition
are prepared for it to be null). 

Note: this bug was discovered with a profiler using 2.1.1. Since its relatively 
minor, I'm suggesting it be fixed only with verion 3.0. 

Since the proposed fix is so small, I've included the patch output here:

Index: AbstractTextEditor.java
===================================================================
RCS file: /home/eclipse/org.eclipse.ui.workbench.
texteditor/src/org/eclipse/ui/texteditor/AbstractTextEditor.java,v
retrieving revision 1.65
diff -u -r1.65 AbstractTextEditor.java
--- AbstractTextEditor.java	7 Jul 2003 21:21:33 -0000	1.65
+++ AbstractTextEditor.java	14 Jul 2003 04:21:49 -0000
@@ -385,7 +385,10 @@
 								// pos is null
 							}
 						}
+						// note: during dispose the LastEditPosition is set to 
null, 
+						// so the TextEditorPlugin does not "hold on to" the 
Document in Selection
 						TextEditorPlugin.getDefault().setLastEditPosition(new 
EditPosition(input, getEditorSite().getId(), getSelectionProvider().
getSelection(), pos));
+						fLastEditPositionAdded = true;
 					}
 				}
 			}
@@ -1447,6 +1450,13 @@
 	 * @since 2.1
 	 */
 	private String[] fKeyBindingScopes;
+	/**
+	 * Remember if this instance set the last edit
+	 * position, so it can be set to null during 
+	 * dispose, if it did set it.
+	 * @since 3.0
+	 */
+	private boolean fLastEditPositionAdded;
 	/** 
 	 * The editor's insert mode.
 	 * @since 3.0
@@ -2648,6 +2658,14 @@
 		
 		if (fEditorStatusLine != null)
 			fEditorStatusLine= null;
+
+		if (fLastEditPositionAdded) {
+			// in case last edit position was set, which might 
+			// be holding on to Selectin (which hold on to Document).
+			// And, we don't want to set to null, unless we 
+			// were the ones to set it. 
+			TextEditorPlugin.getDefault().setLastEditPosition(null);
+		}
 		
 		super.setInput(null);
Comment 1 Dani Megert CLA 2004-09-24 11:24:47 EDT
Fixed in HEAD: got rid of selection. The patch would have disabled Go To Last
Edit Position feature once the editor got closed.