Extreme memory usage

Aug 24, 2010 at 3:26 PM

Hi there,


I have a ContentControl which is bound to ActiveItem. Everytime ActiveItem is changed, new View is created.

So basically, if you have a DataGrid with 1000 view model items (which are derived from Screen to visualise details view), you'll end up creating 1000 views, cached inside.

Multiply these with 20 view model folders - different grid views - you'll end up with 20000 views, cached inside.

So basically, everything is getting cached, what finally leads to OutOfMemory exception.


The question is, how to disable View caching, without breaking whole architecture of Caliburn. Shouldn't it  be possible to reuse same types of views, right?

Or View+ViewModel binding is one time only?

Aug 24, 2010 at 3:31 PM

It's hard to make a recommendation, not knowing all the details, but you can turn off the caching. Override the SetView method on Screen and do not call the base. This is where the view gets stored. Also, I don't normally use Screens for items in a DataGrid. You can still use a Conductor without using a Screen if you want the conductor's functionality. Then, you just implement the interfaces you care about (IActivate, IDeactivate, IHaveDisplayName, IGuardClose, IViewAware, INPC) on the item or none if you don't need them.

Aug 24, 2010 at 3:53 PM

I've tried to do just as you've said, but...

1) Views are still referenced, probably because of action bindings. So memory is not released.

2) How to avoid recreating of the same View, but just re-bind it to another ViewModel?

Aug 24, 2010 at 5:48 PM

Hmm. Good point about Views being referenced by ActionMessage. I will look into that soon.


Aug 24, 2010 at 5:49 PM

I added a ticket to investigate this further.

Sep 1, 2010 at 3:32 AM
Edited Sep 1, 2010 at 5:10 AM

I ran into the same issue. I called TryClose on a view and later created the screen again and the cached view was shown.

Never mind it was a MEF configuration issue. Forgot to add PartCreationPolicy(CreationPolicy.NonShared) in my Export attribute of an inner view model so it was always coming back with the same inner view model that had modifications.

Sep 1, 2010 at 2:19 PM
Edited Sep 1, 2010 at 2:19 PM

That's something important to point out. If your VM inherits from Screen (or implement IViewAware in a way that caches views) and your VM is a Singeton, it will always use the same view. You can fix this by changing the VM to be transient. Or you could override the IViewAware logic and change how that works...perhaps by clearing out the view when the VM is closed.

Jan 10, 2012 at 1:12 PM

Hi there,

                  I would like to know if this issue was solved... Anyway I don't see any SetView method on Screen. I am using last Caliburn version, and I would like to achieve this kind of functionality on this thread.



Jan 10, 2012 at 1:29 PM

Any known memory issues have been resolved. However, that still means you need to think carefully about your architecture, especially if you are going to have a massive number of components.