Cached Views and UI-Router Resolves

A controller linked to a cached view is NOT re-run upon re-activating the view, however the resolve is run whenever we go to that URL, regardless of whether or not the view is cached.

Most of my routes have resolves, that fetch some data, in my case the data is reactive/has listeners attached to it, mostly instances of my classes that extend angularfire (firebase) objects, giving them built-in listeners for their socket-updates on data changes from the server.

So the problem is, every time I return to a cached view, I’m creating new listeners, that I can’t destroy (because they’re created in the resolves, then never accessed anywhere, but they keep on firing events which trigger scope digests – which of course is quite handy when they are IN a controller, but becomes a massive memory leak (or something even worse because they trigger scope digests!) when they are NOT in a controller, but floating around in the closure of a resolve to a controller that never saw the light of day).

Anyways, it also just seems odd that resolves are even fired on returning to a cached view. I mean, I understand exactly WHY (because this is UI-Router that doesn’t know anything about Ionic, and Ionic’s nav-view’s leave all the actual route handling up to UI-Router), but I’m curious if anyone has any thoughts or ideas as to what a good solution here might be, or if we are saying that with caching one really should just ditch the resolves because it’s one or the other (beyond just my personal garbage collection problem, I’m also waiting while these routes resolve, even if I shouldn’t have to, because the view is cached!).

Thoughts?

2 Likes

+1, along with this State resolving and cached views in Beta-14

did you find a solution to the resolve firing?