Trying to get a handle on memory management with Backbone by using the heap snapshot tool in Chrome. There's a back button on a view which when clicked will switch the current view with a new one via a backbone router.
I take a snapshot on the initial page, navigate to the page with the back button, click the back button and take another snapshot. I'd expect heap snapshot to be identical using the comparison option. However old models/collections seemingly aren't being cleared (they are highlighted in white in the snapshot i.e. still accessible via the root of the graph). Also it looks like the views themselves aren't being removed either(same white highlight in the snapshot).
I've linked a diagram to aid the explanation (https://i.stack.imgur.com/mlN2I.jpg). Say view V1 nests three views of which V2 contains a model M1, V3 holds model M2 and V4 holds a backbone collection C1. M1 listens to a change to M2 and updates itself accordingly. In order to properly remove view V1 the following are done:
- Call Backbone.View.Remove on V1 and all its child views (and the child views of those children if they exist)
- Call Backbone.Events.StopListening on all models (and the child models of those models if they exist)
Is this enough to completely clear the view? It seems like most resources online discuss proper disposal of backbone views but not its models/collections.
Any help would be much appreciated. Thanks.