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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T00:31:13+00:00 2026-05-11T00:31:13+00:00

I was told by a rather smart person that you cannot implement garbage collection

  • 0

I was told by a rather smart person that you cannot implement garbage collection in C because of it’s weakly typed. The basic idea seems to be that C gives you too much freedom. He mentioned casting pointers without type checking…

I don’t really grok the idea. Can someone give me an explanation and possibly a code sample of why this wouldn’t work.

NOTE: Obviously C is about speed and why would you want to add garbage collection? I’m just curious really.

  • 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. 2026-05-11T00:31:14+00:00Added an answer on May 11, 2026 at 12:31 am

    He probably referred to the fact that you can cast a pointer to an int and back to the original pointer type. It’s pretty much impossible for a GC to clean up correctly when you do that, consider:

    char * p = (char *) malloc(16); int i = (int) p; p = 0; // GC runs and finds that the memory is no longer referenced p = (char *) i; // p is now a dangling pointer 

    EDIT: The above will only produce a dangling pointer with a precise GC. As others have pointed out, a conservative collector can still correctly handle this scenario as it assumes that any bit pattern that could be a valid pointer actually is a pointer and will thus not free the memory allocated. However, this is of course no longer possible when i is further modified such that it no longer looks like a valid pointer to the collector, e.g. as follows:

    char * p = (char *) malloc(16); int i = ~((int) p); p = 0; // GC runs and finds that the memory is no longer referenced p = (char *) ~i; // p is now a dangling pointer 

    Moreover, (again as others have pointed out) it’s only impossible to implement a GC for C if you want to retain the full functionality of the language. If you refrain from using tricks like the above (i.e. you confine yourself to a subset of the possible operations) then GC is indeed feasible.

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

Sidebar

Ask A Question

Stats

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

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

    • 7 Answers
  • Editorial Team

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

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Check that you added the extension to the correct php.ini… May 11, 2026 at 8:54 pm
  • Editorial Team
    Editorial Team added an answer Send the good'ol WM_CLOSE to all instances... Process[] processes =… May 11, 2026 at 8:54 pm
  • Editorial Team
    Editorial Team added an answer Which dump are you using? There were problems from the… May 11, 2026 at 8:54 pm

Related Questions

I have only been working with sharepoint for three months but right from the
I recently started learning Python and I was rather surprised to find a 1000
I've implemented a system in C# that uses the Microsoft Message Queue ( System.Messaging
I'm developing a Flex 2 application, and I noticed that part of the library

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.