Add test for garbage collector refcount method and optimize it