Non-metal ion trapping, i.e. using memory material trapping non-metal ions given by the electrode or another layer during a write operation