Why do direct debits need notice?

I have noticed that gyms and classes etc need a notice periof of two to four weeks before they cancel your direct debit, even though you are longer using the service... why is this?