Variables Should Not Be Declared inside the Loops
The following code can result in an error message "Too many new instances created" in the server log:
for (...) { def var = new LinkedHashMap() }
So you should always change it to this form:
def var for (...) { var = [:] }
The technical background is that the first script allocates a new variable which can increase the number of FormulaSandbox instances (above the limit).