There is some controversy over this subject and part of it is how much is manufacturer BS to sell more helmets.
Age and sun will make the foam kind of crumbly, so it's not total BS, but there's no "real" age at which you should replace it.
But a crack in the foam is a definite indicator.