Fixed memory leaks on circular references