main loop and catching up a memory leak