The last of the hydrogen gas in the outer shell is blown away to form a ring around the core. This ring is called a planetary nebula. When the last of the helium atoms in the core are fused into carbon atoms, the medium size star begins to die. Gravity causes the last of the star's matter to collapse inward and compact. This is the white dwarf stage which is extremely dense.
White dwarfs shine with a white hot light but once all of their energy is gone, they die.
The star has now reached the black dwarf phase. Once massive stars reach the red giant phase, the core temperature continues to increase as carbon atoms are formed from the fusion of helium atoms. Gravity continues to pull together the carbon atoms in the core until the temperature reaches 600,000,000 degrees Celsius. At this temperature, carbon atoms form heavy elements such as oxygen and nitrogen. The fusion and production of heavy elements continues until iron starts to form.