When is it time to replace the gear-cable housing? Please keep in mind that this question is specific to mountain bikes which roll through lots of dirt and mud. I heard stories of bikes that had their cable housing last for years, but I doubt that this applies to mountain bikes (or maybe it does).

How would I know when the housing needs to be replaced? Several options occur to me:


As a rule of thumb, always replace the housing together with the cable. The reasoning is probably mostly the low cost of materials which is a few dollars. 
To the other extreme, do not replace the housing unless you get some indication that it needs replacement. For example, visual inspection finds some wear and tear or the cable won't move freely while tugging it. 
Something else.


My current practice is to follow option 1 but I would be interested in knowing if there is perhaps a more efficient option backed by the experience of the masses.
Most quality cable housings now have a plastic lining. This allows the cable to slide freely and prevents binding and rust formation. If you use stainless steel cables they don't rust. My local shop has plain steel cables for $2.99 or stainless for $4.99. I am a big fan of Jagwire cable sets. The mountain sets include a small plastic sleeve for the exposed sections of cable. The housing ends are sealed by a small rubber section that extends into the above mentioned plastic sleeve. There is no way for any grit to enter easily. I change the cables only when there is evidence of fraying or breakage. I have had the same housings for 3 years and they seem to work like the day I put them on.