Carbon Monoxide alarms use an electrochemical detector cell which gives an output current dependent on carbon monoxide concentration. However the electrochemical cell has a limited life (typically 5 years) which is why you have to throw the whole unit way. Most carbon monoxide alarms give some form of indication (light or sound) that they have reached the end of their useful life.
Some carbon monoxide alarms incorporate a user replaceable detector cell, avoiding the need to replace the complete alarm.
Although smoke detectors have no such inherent lifetime limitation, most manufacturers recommend that they are replaced after 10 years.