Files
openide/java/java-impl/resources/inspectionDescriptions/ObjectAllocationInLoop.html
2025-02-05 04:43:28 +00:00

41 lines
1.1 KiB
HTML

<html>
<body>
Reports object or array allocations inside loops. While not
necessarily a problem, an object allocation inside a loop is a great place to look for memory leaks
and performance issues.
<p>
The inspection reports the following constructs:
</p>
<ul>
<li>Explicit allocations via <code>new</code> operator</li>
<li>Methods known to return new object</li>
<li>Instance-bound method references</li>
<li>Lambdas that capture variables or <code>this</code> reference</li>
</ul>
<p><b>Example:</b></p>
<pre><code>
// Explicit allocation
for (Status status : Status.values()) {
declarationsMap.put(status, new ArrayList&lt;&gt;());
}
// Lambda captures variable
String message = "Engine running.";
for (Engine engine : engines) {
if (!isRunning(engine)) {
logger.warn(() -> {
return String.format(message);
});
}
}
// Instance-bound method reference
for(Node node : nodes) {
descriptor = node.getDescription();
descriptor.ifPresent(dynamicTestExecutor::execute);
}
</code>
</pre>
<!-- tooltip end -->
</body>
</html>