Files
openide/java/java-impl/resources/inspectionDescriptions/ThreadLocalSetWithNull.html
Leonid Shalupov 40795fe787 IJI-2422: community/java: move resources under resources root
GitOrigin-RevId: 8b2b63fc6db476ca0c2cfe5cadd84db6c4236d0f
2025-02-05 04:43:28 +00:00

22 lines
856 B
HTML

<html>
<body>
Reports <code>java.lang.ThreadLocal.set()</code> with null as an argument.
<p>This call does not free the resources, and it may cause a memory leak.</p>
It may happen because:
<ul>
<li>Firstly, <code>ThreadLocal.set(null)</code> finds a map associated with the current Thread. If there is no such a map, it will be created</li>
<li>It sets key and value: <code>map.set(this, value)</code>, where <code>this</code> refers to instance of <code>ThreadLocal</code></li>
</ul>
<p><code>java.lang.ThreadLocal.remove()</code> should be used to free the resources.</p>
<p>Example:</p>
<pre><code>
ThreadLocal&lt;Integer&gt; threadLocal = new ThreadLocal&lt;&gt;();
threadLocal.set(null);
</code></pre>
<p>After the quick-fix is applied:</p>
<pre><code>
threadLocal.remove();
</code></pre>
<p><small>New in 2023.2</small></p>
</body>
</html>