0

We are working on a Silverlight application using Silverlight 5 and MVVM Light. There are more than 3000 graphical elements rendered in the view, each with an associated ViewModel. An ItemsControl is used to bind these objects to these view models. When the view is loaded first time, it takes 7 seconds to render the 3000 objects. However when we refresh the view by setting a new view model collection, it takes 17 seconds to render – even if we only render a smaller number of ViewModels this time. The concern here is the 10 second difference between different renderings.

We found when we prevented the ViewModels from being cleaned up by the GC (by adding them to another collection and never releasing them), the subsequent render times were all only 7 seconds as well. So the conclusion from this is that the extra 10 seconds is caused by the garbage collection of the older ViewModels.

From what we’ve seen above it seems the garbage collection is blocking the UI thread. The UI is frozen until the GC finishes its job (we see this as once our temporary logging in the VM Finalizer method is finished) then the UI will resume rendering.

So in summary, our timings are :

Initial 3000 objects – ~7 seconds. Next replace with 500 objects – ~17 seconds.

Initial 500 objects – ~2 seconds. Next replace with 3000 objects – ~7 seconds.

Initial 3000 objects – ~7 seconds. Next replace with 3000 objects – ~17 seconds.

Are there any suggestions around this very odd issue we’re seeing?

kint
  • 1
  • 1

1 Answers1

0

You might need in your case to manually call the garbage collector. It might not have any impact but I would suggest to investigate your code and checking if you could fit it in somewhere clever in your code to see if it has any impact on the load times.

Check this link for calling the GC manually.

Community
  • 1
  • 1
Stainedart
  • 1,929
  • 4
  • 32
  • 53