Stop allocating/deallocating memory inside for-loops