I have moved the code to a new form, and recovered some memory after unloading the form. It solved some of the problem.