Add a unit test for reference counting