def test_reference_cleanup_default_custom_error(self):
        """
        references to encoded objects are cleaned up
        """
        ref = Custom()

        def default(obj):
            raise TypeError

        refcount = sys.getrefcount(ref)
        with pytest.raises(orjson.JSONEncodeError):
            orjson.dumps(ref, default=default)
        assert sys.getrefcount(ref) == refcount

        references to encoded objects are cleaned up
        
test/test_default.py