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 261249
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T22:24:58+00:00 2026-05-11T22:24:58+00:00

I was wondering how a Garbage Collector can be implemented with C++ full power

  • 0

I was wondering how a Garbage Collector can be implemented with C++ full power of pointers arithmetic. Also, In languages like Java, I can not assign literal addresses to references. In C++ it is very flexible.

I believe that C# has both, but again, the unsafe pointer in C# is the responsibility of the programmer.

EITD :: guys, I am asking if C++ pointers ‘as they are currently’ can be GCed in theory or not ?

  • 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-11T22:24:58+00:00Added an answer on May 11, 2026 at 10:24 pm

    Pointer arithmetic isn’t the fundamental problem. GC’s have to deal with pointers being reassigned all the time, and pointer arithmetic is just another example of that. (Of course, if pointer arithmetic between pointers pointing to different buffers was allowed, it would cause problems, but it isn’t. The only arithmetics you’re allowed to perform on a pointer pointing into an array A are the ones that repositions it within that array.

    The real problem is the lack of metadata. A GC has to know what is a pointer and what isn’t.

    If it encounters the value 0x27a2c230, it has to be able to determine if it is

    • a pointer (in which case it has to follow the pointer to mark the destination as “in use” recursively)
    • An integer (The same value is a perfectly valid integer. Perhaps it’s not a pointer at all)
    • or something else, say, a bit of a string.

    It also has to be able to determine the extent of a struct. Assuming that value is a pointer, and it points into another struct, the GC has to be able to determine the size and extent of that struct, so it knows which range of addresses should be scanned for more pointers.

    GC’ed languages have a lot of infrastructure to deal with this. C++ doesn’t.

    Boehm’s GC is the closest you can generally get, and it it is conservative in that if something might be a pointer, the GC assumes it to be one, which means some data is needlessly kept alive. And so, it will likely keep data alive which should be GC’ed.

    Alternatively, of course all this infrastructure could in principle be added to a C++ compiler. There’s no rule in the standard that it’s not allowed to exist. The problem is that it would be a major performance hit and eliminate a lot of optimization opportunities.

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

Sidebar

Related Questions

I was wondering how the garbage collector in Java deals with the following situation.
I'm wondering what are the exact situations that trigger Full Garbage Collection in Java.
I was wondering if it is possible to tweak the way garbage collector works
I was wondering about the garbage collection that takes place in Java. Is it
Most of the modern languages have built in garbage collection (GC). e.g. Java, .NET
I was thinking about garbage collection on the way home, and I began wondering,
I have a strange doubts. I know garbage collector has its own limitation. and
I'm mainly wondering about the affect that garbage collection would have on performance. Is
I'm not all that familiar with how garbage collection works and what causes memory
I'm not asking this question because of the merits of garbage collection first of

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.