Complex sentence: She stayed at the Academy for Young Ladies for four years (leaving only when the school closed in 1839), and remained a devout Catholic for the rest of her life.
Split into simpler sentences: She stayed at the Academy for Young Ladies for four years, leaving in 1839, when the school closed. She remained a devout Catholic for the rest of her life.