On the existence of closed geodesics on noncompact Riemannian manifolds