I replace mine at 5-7 years, depending on condition. If I crash it properly, replace at once. Also condition of straps and ratchets has to be taken into account – a solid helmet that comes off the straps and your head won’t do much good…
And if the EPS parts have lots of small nicks and bumps, replace. I usually have 2-4 helmets in use / rotation, and I replace them from the oldest when they start to look worn down in general.
I have also forced some friends to replace theirs, when they were looking more like potato fields on the outside – once a friend did a full flip forward over the bars and smacked to pieces the helmet I had given him a couple of weeks before. He was happy I did.
I also like to hammer-test the helmets when I bin them – some road helmets were so easy to crack to pieces that I mostly ride with a MTB helmet on the road too – just removed the visor. My favourite at the moment is the Endura MT500 Koroyd + MIPS version, it is an awesome helmet, fit-wise and durability-wise.