WinJS ListView Garbage Collection

August 2
blog author



When making hybrid apps with WinJS and any other framework, there are ways to do things that we may want to keep from our framework of choice, in my case SproutCore. Navigating to different pages means removing a MainPane and appending another. This makes sense because it removes it from the DOM and puts it into memory to help performance. But when using this approach, I was presented with a bunch of null reference errors which stumped me for a while. Trying to reference the winControl again causes another error because the left over DOM is still partially there. With a little investigation, we found that WinJS ListViews are marked as 'zombie'd and will automatically get destroyed. Instead of removing a pane, I hid it with the isVisible property. This will keep the WinJS ListView alive so I can reference it again. I'm looking into other ways to go about this, but this is my solution so far and it works fine. There's always room for improvement. If you're starting out with WinJS development, the samples from Microsoft are a great resource.