Discussion Board

Results 1 to 7 of 7
  1. #1
    Regular Contributor
    Join Date
    Oct 2013
    Location
    Pennsauken, NJ, USA
    Posts
    124

    VirtualizingStackPanel + FlipView recycling problem

    I am trying to achieve a list of images (much like the Pictures hub) from a zip or rar archive containing jpg files in a WP8 universal app. I've already got a so-so solution using a custom control in a Silverlight app, but I wanted to try the FlipView to get much nicer animations (scrolling, snapping, snap-back). However, I'm seeing a big problem with the virtualization from the VirtualizingStackPanel inside the FlipView.

    My setup:
    The ItemsSource property of the FlipView is bound to a List of custom class type VirtualizedItem. My VirtualizedItem contains an ImageSource get accessor that extracts an image from an archive (rar file) and loads it to a BitmapImage with screen-width dimensions. I've got the CleanUpVirtualizedItemEvent setup to clear the ImageSource when the item is revirtualized. This should work...

    And it does seem to be working in terms of memory requirements. I can flip through the images and get to the end of my list of 30 or so images. However, there is something wrong with the virtualization. If I flip back and forth a few times, eventually one of the images will show up out of order. What seems to be happening is this:

    Let's say that the current unvirtualized items are #3, #4, and #5. If I flip forward, then backwards, sometimes image #6 will show up where image #3 should be. It seems that the flip forward virtualizes #3 and starts the load for image #6, but the quick flip back causes that image load for #6 to show up back at #3 which has been newly unvirtualized.

    Any suggestions on how I should fix this problem?

  2. #2
    Regular Contributor
    Join Date
    Oct 2013
    Location
    Pennsauken, NJ, USA
    Posts
    124

    Re: VirtualizingStackPanel + FlipView recycling problem

    I've narrowed the problem down to VirtualizingStackPanel with perhaps the internal scrollviewer snapping. I replaced the FlipView with an ItemsControl and it does the same thing. I wish I knew exactly how VirtualizingStackPanel worked in WinRT.

    *edit- tweaked things and now it's not doing the disordered items anymore. I wish I knew exactly which setting did it.
    Last edited by leemcpherson; 2014-05-10 at 03:53.

  3. #3
    Regular Contributor
    Join Date
    Oct 2013
    Location
    Pennsauken, NJ, USA
    Posts
    124

    Re: VirtualizingStackPanel + FlipView recycling problem

    Oh well, I ended up not using VirtualizingStackPanel at all. I switched to a regular StackPanel and handled loading and unloading of images manually.

    FYI, the new WinRT/Universal Apps version of Windows Phone is AMAZING! There's a few new things to learn how to do, but memory management is so much easier! I don't know if the Silverlight apps for 8.1 has improved this much.

  4. #4
    Nokia Developer Champion
    Join Date
    Mar 2013
    Posts
    529

    Re: VirtualizingStackPanel + FlipView recycling problem

    Just out of curiosity: in what way do you feel that memory management is easier. Given that both stacks are using Garbage Collection (at least when used from C#, with C++/WinRT it would be Reference Counting) memory management has always been the least of my concerns. I'm curious though if there is something that I have been missing so far.

  5. #5
    Regular Contributor
    Join Date
    Oct 2013
    Location
    Pennsauken, NJ, USA
    Posts
    124

    Re: VirtualizingStackPanel + FlipView recycling problem

    The only flaw in WP8 was disposing a BitmapImage. You can do a search on StackOverflow for these problems, but when you tried to free memory by setting a BitmapImage to null, the memory was not actually freed. Even calling GC.Collect didn't do it... immediately. As a result, if your app was loading and unloading several large images in succession, you'd go over the memory limit fairly quickly. There were some interesting hacks to get around this problem. One was to set the source of an already opened BItmapImage with a 1x1 pixel png file to forcefully release the memory the old image was holding on to.

    With WinRT and 8.1, I haven't run into any of those problems yet. I'm not sure if they fixed this quirk of a BitmapImage or if the way garbage collection works now makes it better.

  6. #6
    Nokia Developer Champion
    Join Date
    Mar 2013
    Posts
    529

    Re: VirtualizingStackPanel + FlipView recycling problem

    Silverlight has a managed XAML-implementation, WinRT however has that in native code (with Reference Counting). So I guess that the problem is being solved by that (e.g. Reference is removed an memory is reclaimed due to the reference counter going to zero). Thanks for the info on your experience with this.

  7. #7
    Nokia Developer Moderator
    Join Date
    Oct 2006
    Location
    Finland
    Posts
    4,573

    Re: VirtualizingStackPanel + FlipView recycling problem

    For the record, this thread has been featured and its details are here

Similar Threads

  1. Recycling in commandAction()
    By vineetbillorey in forum Mobile Java General
    Replies: 2
    Last Post: 2009-04-15, 13:47
  2. recycling nokia 5510 display
    By smeaggie in forum General Development Questions
    Replies: 1
    Last Post: 2004-07-30, 08:05

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×