Revert "Revert "start adding reference counter to resource management""

This reverts commit ccedbcbd3098b8778d024de9a179c6f9d6b6a769.