found another bug. added garbage collection method. tested valgrind. it worked.