You have to "land" as a Permanent Resident prior to your Confirmation of Permanent Residence (COPR) expiring. You can leave after you do the paperwork, but:
1) you must still meet the residency requirements (ie, live in Canada for 2 out of every 5 years)
and
2) it is very difficult to be hired while out of Canada in most cases.