According to this answer, ASP.NET MVC creates a new instance of the controller class to respond to each request.
My question is, when does the controller instance get destroyed?
So far, I've been assuming (perhaps incorrectly) that these instances are destroyed at the end of each response, but some database pool issues I'm having lead me to think that perhaps they are left for the garbage collector. Does anyone have any insights on this?
The controller is left to be cleaned up by the garbage collector. But if you were to issue a new request before the old controller is cleaned up it should not affect your new request since a new controller with a fresh context will be created for that new request.
If you are having DB issues, it may come from how you handle reading/writing to the DB on your back-end. A DB context 'A' is not aware of the changes happening in another DB context 'B' if A was instantiated before changes in B took place. Not sure if that is the problem you are getting though.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With