Controller code execution - history

I’m using Ionic for the first time for developing an hybrid app.

I’m a bit confusing about how controller data are managed from Ionic when a previous visited state is requested by calling $state.go or is accessed by back navigation functionality of Ionic.

Until now, i didn’t understand well in wich cases the code into the controller are executed again and how I can control it.

Thanks in advance