Residency is not well defined. Whether you own property in the state you leave matters. If you earn no income in California and sell your primary residence, you terminate your California residency by establishing it elsewhere - move to another state, 1) establishing an address 2) domiciling your financial accounts, 3) registering to vote, 4) obtaining your driver's license, 5) registering your vehicle
Leaving the country is a bit more challenging, because some states automatically assume (to their convenience) that you remain a permanent resident of that state. You can first relocate to another state, establish residency there, and then leave the US. This is easier when you have family members in the new state with an address you can use as a base. Otherwise, you move abroad and do the same things as mentioned above: financial domicile, drivers license, voting registration. In addition, all US Embassy and Consular offices have a registration file where you can sign up (for notifications and information) - this helps. Patriot Act make establishing an overseas address onerous, but not impossible for financial accounts.
There have been many threads here on this - try searching. One example State Residency and Taxes???html
Martha and Kramer are particularly knowledgeable on this.
Some very good threads over at RADDR's site as well. Look for posts by Kramer on both state residency and moving abroad. Here's one Raddr's Early Retirement and Financial Strategy Board :: View topic - State residency