'Return a finalizer function that will release references to
related compiled functions.'

def _make_finalizer(self):

    overloads = self.overloads
    targetctx = self.targetctx
    def finalizer(shutting_down=utils.shutting_down):
        if shutting_down():
            return
        for cres in overloads.values():
            try:
                targetctx.remove_user_function(cres.entry_point)
            except KeyError:
                pass
    return finalizer
