Whenever there is an interchange between the potential energy and kinetic energy, the total mechanical energy remains constant. This is principle of conservation of mechanical energy.
i.e K + U = constant provided there are no frictional forces.
The condition for mechanical energy to be conserved is that there should be no frictional forces. This condition is only applicable in vacuum.