Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

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.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4271814
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T07:29:35+00:00 2026-05-21T07:29:35+00:00

I’m not all that familiar with how garbage collection works and what causes memory

  • 0

I’m not all that familiar with how garbage collection works and what causes memory leaks. But I’m at the point were I’m becoming concerned about it and want to write more efficient code. So the project I’m working on, which is an Asp.Net web application, has an instance of a custom DataCriteria being created when a Session starts in the global.asax and is then stored in a Session variable. This custom DataCriteria is what we are using to communicate with the database for the CRUD methods.

First question is, say we have a Person class, and in this Person class there is a DataCriteria field which is set to the Session variable instance of the DataCriteria. Since an instance of Person holds a reference to an instance of the DataCriteria that will not get disposed of till Session ends, will that instance of Person be able to be collected. Or will every instance of Person not be disposed of till that Session ends.

Second question is more general, but same issue. Basically I’m wondering will a variable that is declared in a method that references the Session variable instance of the DataCriteria be able to be collected by the GC? Or will it too stay till the Session ends?

I thank you for all the advise you can give me here. And if you know of any good reads for understanding Garbage Collection and avoiding memory leaks I would love to hear about them too.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T07:29:36+00:00Added an answer on May 21, 2026 at 7:29 am

    The references held by an object do not affect its availability for garbage collection. However, the inverse is not true. For example, let’s say an instance A has a field that holds an instance B. A will become available for garbage collection as soon as nothing else references it, even if B is static or otherwise “long lived”. However, B will not become available for garbage collection at least until A becomes available for garbage collection.

    Where things can get a bit odd is where references are not too obvious. For example, an instance C becomes referenced by an instance D when C subscribes to an event exposed by D. This means that, if D is long-lived, C will not become available for garbage collection before D unless it unsubscribes from the event. References held via events and other delegates actually account for most of the “memory” leaks in .NET applications. (Properly speaking, these aren’t really memory leaks since there is no actual failure to clean up memory that is not used by actual object instances.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I need a function that will clean a strings' special characters. I do NOT
Let's say I'm outputting a post title and in our database, it's Hello Y’all
I want to count how many characters a certain string has in PHP, but
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a small JavaScript validation script that validates inputs based on Regex. I
I've got a string that has curly quotes in it. I'd like to replace

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.