How long after the election does a presidential candidate have secret service protection?

In the case of Senator McCain, his secret service protection was gone overnight. He was photographed the next morning driving his Toyota SUV out of a hotel garage with Senator Graham- no protection in sight. Senator Clinton did not lose SS protection when she withdrew due to her status as a former first lady.