code: private Membership removeMembership(Session session, String id, boolean broadcast) throws Exception
     {
        MembershipByUserGroupTypeWrapper mWrapper;
        try
        {
           mWrapper = findMembership(session, id);
        }
        catch (ItemNotFoundException e)
        {
           return null;
        }
        catch (PathNotFoundException e)
        {
           return null;
        }
  
        if (broadcast)
        {
           preDelete(mWrapper.membership);
        }
  
        removeMembership(mWrapper.refUserNode, mWrapper.refTypeNode);
        session.save();
  
        removeFromCache(mWrapper.membership);
  
        if (broadcast)
        {
           postDelete(mWrapper.membership);
        }
  
        return mWrapper.membership;
     }
docs: Remove memberships entity by identifier.