Instance variables belong to object instances. When you restart the layout, object instances are destroyed and created again. That's why the variables reset.
You can use global variables to store values which should not reset. Or data objects - arrays, dictionaries, JSON.
Another option is to set your object as Global. It will not be destroyed as you restart or go to another layout. But be very careful, make sure that you are not creating multiple duplicates of this global object with every restart. Use Debug Mode to check.