Fix debug crash due to ref miscounting
Merge pull request #433 from zrax/refcnt

Fix debug crash due to ref miscounting