@staticmethod
def _refcount(tape):
    """ count number of references to any variables on a tape """
    d = {}
    for record in tape:
        for name, value in record.items():
            uid = id(value)
            d[uid] = d.get(uid, 0) + 1
    return d
