Gravitational red shift question

Why does the frequency of a photon emitted from the surface of a star decrease as it moves away from the star?
if hf`=hf(1-GM/(R*c^2)
then as the distance becomes larger, R becomes larger, so f`becomes smaller?

We use the fact that the total energy must remain constant.
I'm not 100% sure, but I think t hat when leaving the star, the photon has to get out of the gravitation-field of the star, therefore its kinetic energy has to decrease since the potential energy is rising.