Gary, signed by Harry Redknapp in October 1999 from Benfica for £1.2 million, recovered from a double hernia operation as he made his move to the club.
But he got was injured while making his debut against Birmingham City and since then the former Nottingham Forest, Derby County and Aston Villa right back has suffered a series of other injury problems that have limited him to just one Worthington Cup and a mere five Premiership appearances.
Gary, who won two full England caps in 1991, was once a match day mascot at Upton Park in the early 1980s, and is a lifelong Hammers fan.
He says:
"West Ham United is a great club and I've thoroughly enjoyed my time here, despite the problems.
"I will always be a Hammers fan and aim to get to as many games as possible."
MD Paul Aldridge adds:
"We wish Gary all the best for the future; he hasn't had the best of times since coming here and it is a shame that his career has come to an end without us seeing the best of him."
Gary's retirement follows hot on the heels of former keeper Craig Forrest, whose testicular cancer caused him to conclude that he could no longer carry on as a professional.