If I have an object stored in memory, and I walk away from my application for an hour, will the object still be there when I get back?
In other words, will the .NET garbage collector throw my object away because it hasn’t been used for awhile?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The garbage collector only collects objects that are no longer referenced in your application. The garbage collector will never collect any objects that are being used.
The garbage collector’s definition of “being used” is based on roots. An object instance has roots if other object instances in the AppDomain reference it. As long as the AppDomain that hosts your application is not unloaded, any and all object instances that were in memory will remain in memory as long as they retain roots in the application.