Funny you should ask. I just did a segment on my show about that very same thing. Most manufacturers say 5 years but in reality the only defining factors are the following that would cause you to change helmets.
1. If the helmet has been in a crash and the exterior is messed up a new one is in order.
2. If the lining has been so compressed and wron that the helmet does not fit properly (IE: sits so low on your head that it obstructs your view or hits the back of your jackets collar) then it's time for a change.
Here's what I did recently when confronted by item #2. I have a custom painted Nolan Classic 100 which is about 4 years old. I spent good money at the painters to customize Wardie etc. and racing stuff so I don't want to throw all that away if I don't have to. I removed the old, compressed not so good liner to reveal and a perfectly good styrofoam interior. I called CIMA International and was able to order an N102 interior at a cost of $35. It took me about 1/2 hour to fit it properly. The end result was that I was able to keep a helmet that I liked and upgraded it to a new more modern interior that fit like a glove. Wardie 101