Hi, @mhartington I finally got a solution to my perculiar problem. With the information I gave you it would have been impossible for you to figure out what the issue was. But I’ll just post it here for anyone who might come across the same issue. I’ll try be as succinct as possible - I actually have a follow up question which is more of an information question though.
I was working on a pattern using a centralised approach to all my all my web requests in the app, which involved using sqlite and events (based on the Google I/O 2010 Rest Talk https://dl.google.com/googleio/2010/android-developing-RESTful-android-apps.pdf). This architecture required a heavy use of events. (more specifically $rootScope.$emit
and $rootScope.$on
.
The use of $rootScope
events seems to be the source of events. I had read somewhere that in angular it is good practice to always destroy $rootScope
listeners in the $destroy
event of the scope belonging to the controller. I was doing exactly that for my $rootScope
events which were carrying notifications of my REST results being ready.
I was able to solve my issue (cached views not being reloaded when navigating back) by deregistering my $rootScope
listeners in the $ionicView.beforeLeave
event. As soon as I did this my cached views were being restored.
Now here comes the speculation: I’m assuming that therefore my issue was basically a memory leak issue between scopes. From my understanding of the ionic framework, caching works in the sense that controllers are actually never destroyed, therefore my listeners relating to a certain scope were carried on to other scopes, thus leaking memory. Please correct me if I’m wrong.
My question now is just to help me understand. How does the history work, if a controller is never destroyed, how does it connect to a new scope. When you navigate back, is the initialisation code in the controller run again? If so what if you had queried persistent data which has now changed?
To answer my question please use this use case to set context.
Assume that we create a Facebook clone in ionic.
- Starting from Newsfeed I click on Kholofelo’s name (A)
- On Kholofelo’s (A) personal feed, I click on his friend Keneiloe’s name (B)
- On Keneiloe’s (B) personal feed I click on her friend Ivy’s name ©
- On Ivy’s personal feed I then click the back button (which should take me back to Keneiloe (B))
Let’s assume that The personal feed page is a used for all personal feeds, and as such the same controller, lets call it ProfileController. the state is newsfeed.profile
with a parameter id
which is the user ID. So in this case, how does the controller and scope get reused.
I know this is very long - but I’ll really appreciate a reply. I can’t seem to find this information and it would really help me if I do get it.