/
Put "def" Outside of Loops

Put "def" Outside of Loops

Since the calculation counts the objects count whenever a new instance is created, you may reach the limit and get an error about too many instances. To avoid this problem, put "def" outside the loops or closures.

So instead of doing:

Too many instances
for (record in records) { def cost = .... }

Use this approach:

Safer approach
def cost for (record in records) { cost = .... }



Related content

List.find() Closure vs. Map.get()
List.find() Closure vs. Map.get()
More like this
How I can resolve 'too many new instances created: 503" error?
How I can resolve 'too many new instances created: 503" error?
More like this
Third Iteration – Further Performance Boost
Third Iteration – Further Performance Boost
More like this

Found an issue in documentation? Write to us.