Add reference counting to solve gc problem