Origin of oxygen vacancies in resistive switching memory devices