Don't leak Repository and RevWalk instances during notedb parsing

Change-Id: Ia8d99f0387206295678234a549dc22a062e5655b
This commit is contained in:
Dave Borowitz
2014-07-31 11:06:39 -07:00
parent 9d5201620f
commit 05b4b4b78d
2 changed files with 23 additions and 12 deletions

View File

@@ -68,7 +68,7 @@ public class DraftCommentNotes extends AbstractChangeNotes<DraftCommentNotes> {
}
}
private static class Parser {
private static class Parser implements AutoCloseable {
private final Change.Id changeId;
private final ObjectId tip;
private final RevWalk walk;
@@ -92,6 +92,11 @@ public class DraftCommentNotes extends AbstractChangeNotes<DraftCommentNotes> {
draftPsComments = ArrayListMultimap.create();
}
@Override
public void close() {
repo.close();
}
private void parseDraftComments() throws IOException, ConfigInvalidException {
walk.markStart(walk.parseCommit(tip));
noteMap = CommentsInNotesUtil.parseCommentsFromNotes(repo,
@@ -167,13 +172,16 @@ public class DraftCommentNotes extends AbstractChangeNotes<DraftCommentNotes> {
}
RevWalk walk = new RevWalk(reader);
Parser parser = new Parser(getChangeId(), walk, rev, repoManager,
draftsProject, author);
parser.parseDraftComments();
try (Parser parser = new Parser(getChangeId(), walk, rev, repoManager,
draftsProject, author)) {
parser.parseDraftComments();
buildCommentTable(draftBaseComments, parser.draftBaseComments);
buildCommentTable(draftPsComments, parser.draftPsComments);
noteMap = parser.noteMap;
buildCommentTable(draftBaseComments, parser.draftBaseComments);
buildCommentTable(draftPsComments, parser.draftPsComments);
noteMap = parser.noteMap;
} finally {
walk.release();
}
}
@Override