C # garbage collection | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 4

C # garbage collection

Can you garbage collect static objects in C#?

2nd May 2020, 3:08 AM
Sanjay Kamath
Sanjay Kamath - avatar
6 Answers
+ 7
Sanjay Kamath My understanding is static objects are always referenced for the life of the application and therefore not released to be garbage collected.
2nd May 2020, 4:06 AM
David Carroll
David Carroll - avatar
+ 3
David Carroll What about Session objects? 🤔
3rd May 2020, 3:27 AM
Sanjay Kamath
Sanjay Kamath - avatar
+ 3
David Carroll session_onstart to session_onend
3rd May 2020, 10:42 AM
Sanjay Kamath
Sanjay Kamath - avatar
+ 3
David Carroll Well... What is an object in an application without a Life-Cycle? 🚴
5th May 2020, 12:11 PM
Sanjay Kamath
Sanjay Kamath - avatar
+ 2
I'm assuming you're referring to ASP.NET session state events from System.Web. However, I'm not making the connection on what that has to do with the garbage collection on static objects in C# or my original response to this question post. You're going to need to provide clearer context with your followup question, which was simply stated as: "What about Session Objects?" To which I can only respond with: What about them? Please put a little more effort in your question. It will go a lot smoother when seeking responses. 🤓👌
3rd May 2020, 1:43 PM
David Carroll
David Carroll - avatar
+ 1
What do you mean by session object?
3rd May 2020, 7:19 AM
David Carroll
David Carroll - avatar