So basically when a star collapses on itself it's called a supernova, and in a supernova the hydrocarbon particles such as magnesium and hydrogen conglomerate in the center horizon of the star, and the star goes through potential energy conservation where the mass has to get rid of the hydrocarbons. This all coexists into a scenario where the star has to explode, or else the hydrocarbons would release space dust that is unwanted.