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

  • Home
  • SEARCH
  • 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 187427

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T15:49:18+00:00 2026-05-11T15:49:18+00:00

How smart is Garbage Collection when it comes to nested references? Take this code

  • 0

How smart is Garbage Collection when it comes to nested references?

Take this code for example:

Public Class SomeClass     Private m_SomeOtherClass(Me) End Class 

I know that GC works by looking at how many references remain, and any object without any references ends up getting dumped. So in this case, where there’s a reference coming from a member variable, is that a memory leak waiting to happen (unless you implement IDisposable, etc)?

Right now I’m assuming that the GC is smart enough for this, since it could probably check to see if any references are coming from the object itself, and just not count them towards the reference count. But I thought I would dig a little.

  • 0 0 Answers
  • 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. 2026-05-11T15:49:18+00:00Added an answer on May 11, 2026 at 3:49 pm

    Basic answer: It’s not a problem.

    I’ve heard this kind of question before and it stems from a confusion with Reference Counting, where circular referencing does pose a problem.

    The .NET collector doesn’t count references, it just scans and flags referenced objects. Those flags also prevent it from going into a loop. This is a very simple and virtually foolproof mechanism. The system doesn’t need to count or track inbound references, so there is zero overhead for shortlived references. But you have to keep an eye on where references exist, a common problem are objects that subscribe to events. The event keeps a reference, so you need to unsubscribe before the subscribing object can be reclaimed. Another benefit of GC is that the logic also works in reverse: whenever your code has access to a reference that reference is guaranteed to be valid, simply because that reference exists.

    Reference counting requires the compiler to inject code every time a reference is changed, copied or goes out of scope, incurring a constant overhead. When the count drops to zero the object can be immediately destroyed. The system needs a mechanism to (manually) handle cycles. You can find some horror stories by searching for the COM IUnknown interface.

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

Sidebar

Ask A Question

Stats

  • Questions 209k
  • Answers 209k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer you can use callback which checks on leaving field if… May 12, 2026 at 9:45 pm
  • Editorial Team
    Editorial Team added an answer "Import..." the existing project then "Share..." the project. The Subversive… May 12, 2026 at 9:45 pm
  • Editorial Team
    Editorial Team added an answer I believe your problem has to do with the fact… May 12, 2026 at 9:45 pm

Related Questions

What's the simplest way to preserve a NHibernate ISessionFactory for web pages and web
I'm rolling my own logger class, and want to represent the heirarchy of logs
I want to make a compiled language. I am currently evaluating backends. So far
How can I fix this RegEx to optionally capture a file extension? I am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.