This thread looks to be a little on the old side and therefore may no longer be relevant. Please see if there is a newer thread on the subject and ensure you're using the most recent build of any software if your question regards a particular product.
This thread has been locked and is no longer accepting new posts, if you have a question regarding this topic please email us at support@mindscape.co.nz
|
I've noticed that after changing the ItemsSource on the DataGrid, my process' memory continues to grow. I've tried an explicit garbage collection, but it seems as though the DataGrid maintains a reference to the previous ItemsSource collection (it may be something very different). I know that the memory is cleaned up if the DataGrid.ItemsSource is not bound to the collection. Please see the attached project. Thanks! |
|
|
Hello Jared Thanks for pointing out this issue. I was able to reproduce this issue where each time the button is pressed the process memory goes up by about 0.1 GB but never went back down. I believe I have fixed this issue. When I try to reproduce it again, every few clicks, the memory drops right back down again. No explicit garbage collection is required. This fix will be available through the next nightly build. Jason Fauchelle |
|
|
Jason, this was a major improvement! Thank you! I did notice (easier to identify when I increase the number of items: 5,000,000) that all the memory is not reclaimed. Each time you hit the "Get Data" button in the example project memory grows, and is occasionally reclaimed during garbage collection, but overall the memory continues to increase. Also, after running several times, I'm getting an OutOfMemory exception. I would expect to be able to run over and over again without running into the OutOfMemory exception. Could there be anything else not releasing a reference so that the garbage collector can't reclaim the memory? Thanks! |
|
|
Hello Jared I'll get back to you about this early next week. Jason Fauchelle |
|
|
Thanks Jason for looking into it! I've also notices that when the ItemsSource is changed, the DataGrid.SelectedItem doesn't get set to null. It still refereces the selected item from the previous items source collection. I was expecting the SelectedItem property to be null when there is nothing selected/highlighted on the screen. Thanks! |
|
|
Hello Jared Using your repro project with 5,000,000 items, we have also observed that after changing the ItemsSource several times, the previous collection is successfully destroyed, but the overall memory slightly increases. This increase in memory was very small though. After each click, the memory only increased by about 10Kb. Also, after about 4 clicks, the memory did not increase by so much. By leaving the application running for a while, the memory slowly drops again. Can you confirm the memory increase was quite small? or were you experiencing a much larger increase in memory each time? We have run the application through a memory profiler and haven't found anything that is still being held onto from the previous ItemsSource. The slight increase in memory may be normal activity. As for the memory exception, we were only able to reproduce this by clicking the button many times in quick succession. This is caused by the event handler for the button being called many times at once without giving the garbage collector a chance to release the memory. This blocks up the application memory with instances of Container. To avoid this, your application should not allow this to occur. In your repro for example, you can lock the event handler code so it can not be run unless the previous run has finished. By doing this we were unable to reproduce the out of memory exception again. The next nightly build will have a fix for setting the SelectedItem to null when the items source changes. Jason Fauchelle |
|
|
Thanks Jason for the reply. Yes I can confirm that the memory increase is quite small. I am glad you ran it through a memory profiler and didn't see anything out of line. The repro project was a large exaggeration to exploit the memory not being reclaimed initially when the ItemsSource was changed...You have resolved that issue. I was seeing small increases in memory that didn't seem to be reclaimed, but it sounds like after leaving the application running for a while it does in fact get cleaned up. I'm not too worried about it. Your previous change made a HUGE difference. Thank you. As for setting the SelectedItem to null when the ItemsSource changes, I've tested the change and it seems to work well. Thank you for resolving the issue! You guys have been great! |
|