Memory B cells are generated during the primary immune response. When a pathogen is encountered, B cells are activated and differentiate into plasma cells and memory B cells. Plasma cells produce antibodies to neutralize the pathogen, while memory B cells are retained in the body for long-term immunity.