registry: Free memory at the end of each loop run to prevent mem leak