Best method to reduce object allocation in recursive loop