A good way for a star to divest itself of carbon is by exploding. Massive stars typically end their lives catastrophically as supernovas. What happens is that the core of the star runs out of nuclear fuel and can no longer sustain the enormous pressure needed to hold it up against the weight of its material.
A critical juncture is reached at which the core abruptly gives up and implodes catastrophically to form either a black hole or a neutron star (depending on its initial mass). The overlying material plunges inwards, following the collapsing core, but rebounds and explodes spectacularly, spewing gas into interstellar space.
Stellar cataclysms like this erupt on average two or three times per century per galaxy, and release so much energy that for a few days the stricken star can rival an entire galaxy in its brightness.
Paul Davies, The Goldilocks Enigma