what happens to the loosely held electrons when each ion is heated in the flame

They are moved to higher energy levels of the atom OR they may be moved so far away the atom is ionized. Whether that happens or not depends upon the temperature of the flame.