when to clear or make null asp .net mvc models?
Posted
by SARAVAN
on Stack Overflow
See other posts from Stack Overflow
or by SARAVAN
Published on 2010-03-19T18:56:46Z
Indexed on
2010/03/19
19:01 UTC
Read the original article
Hit count: 231
HI, I am working in an asp .net mvc application. I am using the model and storing some of the values which i need to preserve between the page posts, in the form of datacontexts.
Say my model looks something like this:
public SelectedUser SelectedUserDetails { //get and set has //this.datacontext.data.SelectedUser = ..... //return this.datacontext.data..... }
Now when this model needs to be cleared? I have many such models with many properties and datacontext. But I don't have an idea on when to clear it. Is there a way or an event that can be triggered automatically when the model is not used for a long time?
Oneway I thought is when i navigate away from a page which uses my underlying model, I can clear that model if its no longer used anywhere and initialise it back as needed. But I need to clear almost many models at many points. Is there an automatic way that can clear models when it is no longer used beacuse care can be taken by my code to initialise them when I need them, but I don't know when to clear them when I no longer need them. I need this to get rid of any memory related issues. Any thoughts or comments?
© Stack Overflow or respective owner