That's not true. If I'm in Japan on a work visa, for example, I don't need to leave the country to apply for permanent residency. And Japan is not a country famously welcoming of immigration.