stellar mass loss
A star is not a sealed object that keeps all its material forever. Throughout its life, and especially near the end, a star constantly leaks gas from its surface into space — sometimes a gentle breeze, sometimes a fierce gale. This steady shedding of matter is called stellar mass loss, and it turns out to be one of the most important things stars do, because it is how the elements they make get back out into the galaxy. The Sun does it too, in a mild way, blowing about a million tonnes of itself away every second as the solar wind.
What drives the outflow depends on the star. In hot, massive stars, the intense light pushes on the gas directly — radiation pressure on the atoms drives winds so strong they can carry away a substantial fraction of the star's mass over its short life. In cool giants and AGB stars, the mechanism is different: pulsations lift gas high above the surface, where it cools enough to condense into dust grains, and starlight then pushes on the dust, dragging the gas along. AGB stars can lose mass at staggering rates — up to ten-thousandths of a solar mass per year in their final superwind, stripping away almost their entire outer envelope.
Mass loss decides a star's fate and feeds the galaxy. A star that begins at, say, eight solar masses but sheds most of its envelope can end as a quiet white dwarf instead of exploding, so how much mass a star loses determines whether it dies gently or violently. And the shed material — enriched with carbon, nitrogen, and heavier elements forged inside — drifts into the interstellar medium, where it eventually forms new stars and planets. The atoms in your body were returned to space by the mass loss of stars that died before the Sun was born.
Eta Carinae, one of the most massive and unstable stars known, erupted in the 1840s and threw off more than ten times the Sun's mass in a single event, building the glowing Homunculus Nebula we see around it today. It is mass loss caught in the act, on a colossal scale.
Stars shed gas throughout life; near the end the loss can be torrential.
Mass loss is not the same as a supernova: it is a continuous wind that strips the star over time, whereas a supernova is a single explosion. How much a star loses to wind beforehand strongly affects whether, and how, it explodes at all.