Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLeo Ufimtsev2014-08-08 19:16:24 +0000
committerDavid Williams2014-08-12 03:08:04 +0000
commita9641396efc8b355c8d34003416d5f77d1e7faf4 (patch)
tree6e63f24a2fd509ead94bfe2d40fd5001dbc75ee9
parent5403174c54a34e4705b062b385339c98452e2430 (diff)
downloadeclipse.platform.releng-a9641396efc8b355c8d34003416d5f77d1e7faf4.tar.gz
eclipse.platform.releng-a9641396efc8b355c8d34003416d5f77d1e7faf4.tar.xz
eclipse.platform.releng-a9641396efc8b355c8d34003416d5f77d1e7faf4.zip
Closed a memory leak. (Dissconnect a filebuffer after use). Previously, after 20k files the tool would slow down to a crawling speed. Now it works with even a million files. Change-Id: I88b891118b59c30a4a7747b13fa43753a71bf33f Signed-off-by: Leo Ufimtsev <lufimtse@redhat.com>
-rw-r--r--bundles/org.eclipse.releng.tools/src/org/eclipse/releng/tools/SourceFile.java58
1 files changed, 36 insertions, 22 deletions
diff --git a/bundles/org.eclipse.releng.tools/src/org/eclipse/releng/tools/SourceFile.java b/bundles/org.eclipse.releng.tools/src/org/eclipse/releng/tools/SourceFile.java
index 66f194a6..26deca69 100644
--- a/bundles/org.eclipse.releng.tools/src/org/eclipse/releng/tools/SourceFile.java
+++ b/bundles/org.eclipse.releng.tools/src/org/eclipse/releng/tools/SourceFile.java
@@ -103,20 +103,18 @@ public abstract class SourceFile {
private void initialize() {
textFileBufferManager= FileBuffers.createTextFileBufferManager();
try {
- ITextFileBuffer fileBuffer= getFileBuffer();
- if (fileBuffer == null)
- return;
IDocument document;
try {
- document= fileBuffer.getDocument();
+ //connect file buffer.
+ ITextFileBuffer fileBuffer = openFileBuffer();
+ if (fileBuffer == null)
+ return;
+
+ document = fileBuffer.getDocument();
} finally {
- try {
- textFileBufferManager.disconnect(file.getFullPath(), LocationKind.IFILE, null);
- } catch (CoreException e) {
- e.printStackTrace();
- // continue as we were able to get the file buffer and its document
- }
+ //Close file buffer.
+ closeFileBuffer();
}
lineDelimiter= TextUtilities.getDefaultLineDelimiter(document);
@@ -180,7 +178,13 @@ public abstract class SourceFile {
}
}
- private ITextFileBuffer getFileBuffer() {
+ /**
+ * If this method is called, <b>ensure</b> that you close the file buffer after usage. <br>
+ * Otherwise you leave a memory leak. {@link #closeFileBuffer()}
+ * {@code textFileBufferManager.disconnect(file.getFullPath(), LocationKind.IFILE, null); }
+ * @return
+ */
+ private ITextFileBuffer openFileBuffer() {
try {
textFileBufferManager.connect(file.getFullPath(), LocationKind.IFILE, null);
} catch (CoreException e) {
@@ -197,16 +201,29 @@ public abstract class SourceFile {
}
/**
+ * This should be called before ending a file operation. <br>
+ * Companion function to getFileBuffer();
+ */
+ private void closeFileBuffer() {
+ try {
+ textFileBufferManager.disconnect(file.getFullPath(), LocationKind.IFILE, null);
+ } catch (CoreException e) {
+ e.printStackTrace();
+ }
+ }
+
+
+ /**
* Given the copyright comment, this method inserts it into the right place in the file.
*
* @param copyRightComment the complete comment that will be inserted.
*/
public void insert(String copyRightComment) {
- ITextFileBuffer fileBuffer= getFileBuffer();
- if (fileBuffer == null)
- return;
-
try {
+ ITextFileBuffer fileBuffer= openFileBuffer();
+ if (fileBuffer == null)
+ return;
+
IDocument document= fileBuffer.getDocument();
doInsert(copyRightComment, document);
fileBuffer.commit(null, false);
@@ -217,11 +234,7 @@ public abstract class SourceFile {
} catch (IOException e) {
e.printStackTrace();
} finally {
- try {
- textFileBufferManager.disconnect(file.getFullPath(), LocationKind.IFILE, null);
- } catch (CoreException e) {
- e.printStackTrace();
- }
+ closeFileBuffer();
}
}
@@ -252,7 +265,7 @@ public abstract class SourceFile {
try {
- ITextFileBuffer fileBuffer= getFileBuffer();
+ ITextFileBuffer fileBuffer = openFileBuffer();
if (fileBuffer == null)
return;
@@ -269,8 +282,9 @@ public abstract class SourceFile {
} catch (CoreException e) {
e.printStackTrace();
} finally {
+ closeFileBuffer();
try {
- FileBuffers.getTextFileBufferManager().disconnect(file.getFullPath(), LocationKind.IFILE, null);
+ FileBuffers.getTextFileBufferManager().disconnect(file.getFullPath(), LocationKind.IFILE, null);
} catch (CoreException e) {
e.printStackTrace();
return;

Back to the top