Reset individual items in VirtualQueryableCollectionView?

15 posts, 0 answers
  1. Timothy
    Timothy avatar
    8 posts
    Member since:
    Aug 2011

    Posted 30 Jan 2013 Link to this post

    When a RadGridView's ItemSource is bound to a VirtualQueryableCollectionView, user navigation in the RadGridView causes the VirtualQueryableCollectionView to accumulate loaded objects.  From a memory management perspective we would like to be able to unload objects from the VirtualQueryableCollectionView - for example, we may want to unload anything outside the range of current row index +- 500 on an ongoing basis to limit our memory footprint.

    The use case for this is any application where the user operates iteratively on a large set of large objects.  When moving down the list in the RadGridView, processed rows are never viewed again yet their associated objects remain in memory unavailable to the Garbage Collector. 

    Unloading these objects from the collection should result in the objects being re-fetched by the ItemsLoading event handler if they are required for subsequent display in the RadGridView.
    
    There appears to be no mechanism for identifying which items should and should not be unloaded.  ResetAll does as its name implies  - unloads all items - which is far too heavy handed for our desired behavior.

    Setting an item to null (via RemoveAt(index), Insert(index, null) produces undesired behavior - the item is not refetched when its row is redisplayed, RadGridview displays an "=" in the row, and the item cannot be removed from the VirtualQueryableCollectionView (RemoveAt fails silently). 

    QUESTION:  Is there a mechanism by which ranges of items can be reset in (unloaded from) a VirtualQueryableCollectionView?

    I've accomplished this using reflection to remove items from the the private "loadedIndexes" collection but obviously would NOTdo that in production code.


    Thanks,
    tim
  2. Austin
    Austin avatar
    12 posts
    Member since:
    Aug 2012

    Posted 30 Jan 2013 Link to this post

    Hey Timothy,

    Funny enough I asked this exact same question earlier today.  Here is the thread. 

    http://www.telerik.com/community/forums/wpf/data-virtualization/question-data-virtualization-and-itemsloading.aspx

    I ended up in the same place as you (using reflection to modify the loadedIndexes list).

  3. UI for WPF is Visual Studio 2017 Ready
  4. Timothy
    Timothy avatar
    8 posts
    Member since:
    Aug 2011

    Posted 30 Jan 2013 Link to this post

    I saw the subject of your thread and figured it had to do with a loading issue rather than unloading.  Reading it now I can see that my post is redundant - in a good way.  This is something that needs to be supported and shouldn't be left for tinkering via Reflection.

    Given that the removal of items from the private collection has the desired effect - at least in terms of reloading them, it seems like it would be short work to support a public method that nulls the item and removes its entry from the loadedIndexes collection.  Even without the range overload, that would be VERY helpful (I'll write my own extension that wraps the single item reset if I have to).

    Thanks for pointing this out, Austin.

    Vlad, there are 2 of us now.  How about a Reset(startIndex, count) method???
  5. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 31 Jan 2013 Link to this post

    Hello guys,

     You are absolutely right! 

    We have already ResetItems() method for the virtual collection and we've added ResetItems(startIndex, count) overload. This will be part of our next internal build (next Monday). 

    Thank you once again for your feedback! I've added 2000 Telerik to your accounts. 

    Kind regards,
    Vlad
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  6. Timothy
    Timothy avatar
    8 posts
    Member since:
    Aug 2011

    Posted 31 Jan 2013 Link to this post

    Thanks, Vlad!
  7. Austin
    Austin avatar
    12 posts
    Member since:
    Aug 2012

    Posted 31 Jan 2013 Link to this post

    Sounds great, thanks for the quick action!
  8. Jesse
    Jesse avatar
    4 posts
    Member since:
    Jan 2013

    Posted 31 Jan 2013 Link to this post

    Vlad,

    When you use the new ResetItems(startindex, count) method on a virtual collection will an associated RadGridView control immediately refresh the visible items? If not, what would be the best way to trigger the update to the visible items without resetting the control? In my case I am trying to get the item updates more than I am trying to release resources.

    A possible way to automate the release of unused items would be to have a maximum page count in the collection and you could dispose of the least recently used page when the page count is exceeded. Setting the page count to cover 2 or 3 times the maximum number of viewable items should work nicely for a lot of one-way applications.

    Thanks,

    Jesse
  9. Vlad
    Admin
    Vlad avatar
    11100 posts

    Posted 01 Feb 2013 Link to this post

    Hi,

     Indeed RadGridView will automatically try to reload all reset items if they are in view. 

    Kind regards,
    Vlad
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  10. MarkAtESpecTech
    MarkAtESpecTech avatar
    95 posts
    Member since:
    Jun 2007

    Posted 16 Nov 2014 in reply to Vlad Link to this post

    I would like to use the above suggested approach as well.
    Any chance there is an example like the suggested use in this thread.
    Thanks for the help.
  11. MarkAtESpecTech
    MarkAtESpecTech avatar
    95 posts
    Member since:
    Jun 2007

    Posted 16 Nov 2014 in reply to MarkAtESpecTech Link to this post

    Little more info.

    I have an event log displayed in a grid.
    As time goes by, the event log gets quite large.
    New items are being added via application events and background processes etc.
    The grid shows the newly added records and user of course can scroll through and view all the records.
    I need to keep the memory footprint of the virtual collection small, like suggested above.
    Having a mental lapse on exactly how to do this. Hence the example or approach would be most helpful.
    Hope that helps explain my goal, let me know if more information is required.
    Thanks again,
    Mark.
  12. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 17 Nov 2014 Link to this post

    Hello Mark,

    In order to reset a smaller load size, you can invoke the ResetItems(int startIndex, int count) to reset just some items or the ResetItems() method to reset all of them. 

    Please note that the ResetItems() method will not raise Reset CollectionChange, as the Refresh() will do, however it will set null for all the loaded items. 

    Regards,
    Dimitrina
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  13. MarkAtESpecTech
    MarkAtESpecTech avatar
    95 posts
    Member since:
    Jun 2007

    Posted 17 Nov 2014 in reply to Dimitrina Link to this post

    Thanks for the information.

    I was wondering what event should I be monitoring - do I monitor an event off the radgrid or the virtual collection.

    For example, if table contains say 200,000 and then scroll all the way down to the end of the table then return back to the beginning.

    When and where should I call the reset method?

    Thanks,
    Mark.


  14. MarkAtESpecTech
    MarkAtESpecTech avatar
    95 posts
    Member since:
    Jun 2007

    Posted 19 Nov 2014 in reply to MarkAtESpecTech Link to this post

    An example of using the ResetItems + RadGrid would be great!
    Thanks,
    Mark.
  15. Dimitrina
    Admin
    Dimitrina avatar
    3769 posts

    Posted 19 Nov 2014 Link to this post

    Hello,

    As it turns out there is not a event I can suggest to know when the ResetItems method should be invoked. Basically, the virtual collection was designed for ReadOnly purposes only and it is not recommended to be used in other scenarios when updates are required. 

    I attached a demo project illustrating how to use the ResetItems method.

    Regards,
    Dimitrina
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  16. MarkAtESpecTech
    MarkAtESpecTech avatar
    95 posts
    Member since:
    Jun 2007

    Posted 19 Nov 2014 in reply to Dimitrina Link to this post

    Thanks Vlad, the example is useful.
    I see how it works now.
Back to Top
UI for WPF is Visual Studio 2017 Ready