[
https://issues.apache.org/jira/browse/PDFBOX-1777?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13818984#comment-13818984
]
Robert Scharpf commented on PDFBOX-1777:
----------------------------------------
Sorry, but I did implement thi some time ago. Yes, I removed the final to allow
them to set to null. Allows me to check for null, cannot do this with final.
And I added a close function in org.apache.pdfbox.cos.COSStream:
// begin Robert Scharpf
public void close() {
if (file != null) {
// System.out.println("COSStream.close() file was open!");
try {
file.close();
} catch (Exception e) {
e.printStackTrace();
}
file = null;
}
if (filteredStream != null) {
// System.out.println("COSStream.close() filteredStream was open!");
try {
filteredStream.close();
} catch (Exception e) {
e.printStackTrace();
}
filteredStream = null;
}
if (unFilteredStream != null) {
// System.out.println("COSStream.close() unFilteredStream was
open!");
try {
unFilteredStream.close();
} catch (Exception e) {
e.printStackTrace();
}
unFilteredStream = null;
}
this.clear();
}
// end Robert Scharpf
> memory leak in org.apache.pdfbox.cos.COSDocument
> ------------------------------------------------
>
> Key: PDFBOX-1777
> URL: https://issues.apache.org/jira/browse/PDFBOX-1777
> Project: PDFBox
> Issue Type: Bug
> Components: Parsing
> Affects Versions: 1.8.2
> Environment: Windows 7, Netbeans 7.4
> Reporter: Robert Scharpf
> Priority: Minor
> Labels: patch
> Original Estimate: 2h
> Remaining Estimate: 2h
>
> org.apache.pdfbox.cos.COSDocument.close() does not close the streams and
> causing therefore a growing memory leak. Supposed fix:
> public void close() throws IOException {
> // if (!closed) {
> // scratchFile.close();
> // if (tmpFile != null) {
> // tmpFile.delete();
> // }
> // closed = true;
> // }
> // begin Robert Scharpf
> closed = true;
> if (scratchFile != null) {
> try {
> scratchFile.close();
> } catch (Exception e) {
> }
> }
> scratchFile = null;
> if (tmpFile != null) {
> try {
> tmpFile.delete();
> } catch (Exception e) {
> }
> }
> tmpFile = null;
> List<COSObject> list = getObjectsByType(COSName.OBJ_STM);
> if (list != null) {
> for (COSObject objStream : list) {
> COSStream stream = (COSStream) objStream.getObject();
> stream.close();
> }
> }
> // end Robert Scharpf
> }
--
This message was sent by Atlassian JIRA
(v6.1#6144)