Memory cells are formed after an initial immune response to an antigen. During this response, clonal selection and expansion occur, leading to the formation of effector cells and memory cells. Effector cells are short-lived and handle the immediate response, while memory cells persist long after the infection has been cleared.