Fixed #1032: id_type local reference counting is wrong