<p>The internal <code>java.io.DeleteOnExitHook</code> uses a <code>LinkedHashSet</code> of paths to delete files at when the JVM exits. However, since there is no way to remove entries from the set, it leaks memory when calling <code>deleteOnExit()</code> for every new temp file created by <code>FileManager.saveToFile</code>. To avoid this, try to reuse temp file names (using one per <code>FileManager</code> instance).</p>
<p><code>FileManager.saveToFile</code> appears to be called on average around every 2s, and this probably leaks around 36 + <em>length</em> * 2 bytes for the String object, 36 bytes for the hashtable node and maybe around 10 bytes for the table entry, or 82 + <em>length</em> * 2 ~= 236 bytes for a typical temp file path length on Windows - about 10MB per day.</p>

<hr>

<h4>You can view, comment on, or merge this pull request online at:</h4>
<p>  <a href='https://github.com/bisq-network/bisq/pull/3817'>https://github.com/bisq-network/bisq/pull/3817</a></p>

<h4>Commit Summary</h4>
<ul>
  <li>Remove redundant locking from FileManager.saveToFile</li>
  <li>Reuse temp file names to fix a memory leak caused by deleteOnExit()</li>
</ul>

<h4>File Changes</h4>
<ul>
  <li>
    <strong>M</strong>
    <a href="https://github.com/bisq-network/bisq/pull/3817/files#diff-0">common/src/main/java/bisq/common/storage/FileManager.java</a>
    (26)
  </li>
  <li>
    <strong>M</strong>
    <a href="https://github.com/bisq-network/bisq/pull/3817/files#diff-1">common/src/main/java/bisq/common/storage/FileUtil.java</a>
    (9)
  </li>
</ul>

<h4>Patch Links:</h4>
<ul>
  <li><a href='https://github.com/bisq-network/bisq/pull/3817.patch'>https://github.com/bisq-network/bisq/pull/3817.patch</a></li>
  <li><a href='https://github.com/bisq-network/bisq/pull/3817.diff'>https://github.com/bisq-network/bisq/pull/3817.diff</a></li>
</ul>

<p style="font-size:small;-webkit-text-size-adjust:none;color:#666;">—<br />You are receiving this because you are subscribed to this thread.<br />Reply to this email directly, <a href="https://github.com/bisq-network/bisq/pull/3817?email_source=notifications&email_token=AJFFTNXMOO73NZQGICRCRDDQZVKQ3A5CNFSM4J6EHOS2YY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4ICCZAIQ">view it on GitHub</a>, or <a href="https://github.com/notifications/unsubscribe-auth/AJFFTNUY6NQ4ID2WXVR6JSDQZVKQ3ANCNFSM4J6EHOSQ">unsubscribe</a>.<img src="https://github.com/notifications/beacon/AJFFTNSWV7VD25XL3X777XTQZVKQ3A5CNFSM4J6EHOS2YY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4ICCZAIQ.gif" height="1" width="1" alt="" /></p>
<script type="application/ld+json">[
{
"@context": "http://schema.org",
"@type": "EmailMessage",
"potentialAction": {
"@type": "ViewAction",
"target": "https://github.com/bisq-network/bisq/pull/3817?email_source=notifications\u0026email_token=AJFFTNXMOO73NZQGICRCRDDQZVKQ3A5CNFSM4J6EHOS2YY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4ICCZAIQ",
"url": "https://github.com/bisq-network/bisq/pull/3817?email_source=notifications\u0026email_token=AJFFTNXMOO73NZQGICRCRDDQZVKQ3A5CNFSM4J6EHOS2YY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4ICCZAIQ",
"name": "View Pull Request"
},
"description": "View this Pull Request on GitHub",
"publisher": {
"@type": "Organization",
"name": "GitHub",
"url": "https://github.com"
}
}
]</script>