Winjs List Dispose RRS feed

  • Question

  • I am trying to optimise my app for windows 8. I have a WinJS.Binding.List and a page which will display a filtered projection of that list. Every time I access the page the filter will most likely be different so I want to dispose of the list when I leave the page.

    Here is my filter:

                filteredListViewItems = Data.items.createFiltered(function (item) {
                    if (item.project === certainProject) {
                            return item;

    When I leave the page I then call:


    However if I put a breakpoint inside the function it still runs every time I add an item.

    How can I remove this altogether?

    Monday, March 10, 2014 9:59 PM

All replies

  • Hi r.c.byrne,

    Basically when you navigate to a new page, the previous page would be destroyed by system automatically. I don't think you need to manually dispose the listview items.

    Every time I access the page the filter will most likely be different so I want to dispose of the list when I leave the page.

    -> I saw you have a item.createFiltered() here, can you make sure that every time you navigate to this page, the "item" collection and the "certainProject" keeps same as last time?


    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Tuesday, March 11, 2014 5:33 AM
  • From my testing I dont seem to be experiancing this.

    I have used the grid app template as the base for my app and use WinJS.Navigator.navigate to navigate. When I create a filtered projection of a list on a page, after navigating away from that page the projection of the list still updates when items are added / updated etc.

    The list is also not destroyed, if I declare the list as a variable at the top of a page when I return to the page the list data it still all there. When I navigate back to the page the variable still contains all the data it did when I left.

    I am simple trying to optimise my app as best I can for low powered tablets :) As a quick side question.. is it necessary to remove event listeners on unload? 

    • Edited by r.c.byrne Wednesday, March 12, 2014 11:20 AM
    Wednesday, March 12, 2014 10:18 AM
  • You should use the memory analyzer to test for memory leaks:


    I don't think you'll need to remove the event listeners, but check in the tool.

    When you create the filtered list, you should call List.dispose() on the page when you navigate away, as you are already doing; I'm presuming you are using the template navigation model? Then call dispose in the template page's unload function.

    There seems to be a design issue here with your data model, or an issue with when you are calling createFiltered; if you are disposing of the projected list when you navigate away from the page, the list shouldn't get updated after navigating away (it's disposed of). You might try using the template design (as in Grid/Split/Hub); the page calls getItemsFromGroup(), which is implemented in data.js, which returns a list projection (using createFiltered) that is associated with the page. You should be adding items to your main data source object, and probably not to a projected list that might be disposed of at any time.

    Tuesday, March 25, 2014 11:18 PM