c# - Memoryleak when using ICollectionView with Entity Framework -


so in application use icollectionview of products, bound datagrid databinding. products come ms-sql table , table quiet big (~30.000 entries). @ points need reload table contents might have changed.

whenever call reloadproducts() ~30.000 new objects created. previous objects not freed , remain in memory whole live of application.

any idea how force disposal of old objects?

viewmodel:

private icollectionview _productcollectionview;  public icollectionview productcollectionview  {     set { _productcollectionview = value; }         {         if (_productcollectionview == null)         {             reloadproducts();         }         return _productcollectionview ;     } }  public void reloadproducts() {   list<products> productlist = entities.products.tolist();   productcollectionview = collectionviewsource.getdefaultview(productlist);   notifypropertychanged("productcollectionview"); } 

view:

<datagrid itemssource="{binding productcollectionview}" autogeneratecolumns="false"/> 

try use collection neither it's view. binding connect collection's view on itself.

just use :

    private observablecollection<products> _productcollectionview;      public observablecollection<products> productcollectionview      {         set { _productcollectionview = value; }                 {             if (_productcollectionview == null)             {                 reloadproducts();             }             return _productcollectionview ;         }     }      public void reloadproducts()     {       productcollectionview.clear();       observablecollection<products> productcollectionview =  new observablecollection<products>(entities.products.tolist());     } 

Comments

Popular posts from this blog

magento2 - Magento 2 admin grid add filter to collection -

Android volley - avoid multiple requests of the same kind to the server? -

Combining PHP Registration and Login into one class with multiple functions in one PHP file -