Inspectopedia
 
2024.3

Object allocation in loop

Warning
New
Last modified: 03 December 2024

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.

The inspection reports the following constructs:

  • Explicit allocations via new operator

  • Methods known to return new object

  • Instance-bound method references

  • Lambdas that capture variables or this reference

Example: