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
Post a Comment