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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T00:35:47+00:00 2026-06-09T00:35:47+00:00

Yesterday, we had a discussion on Gargbage collection. It was discussed that the objects

  • 0

Yesterday, we had a discussion on Gargbage collection.

It was discussed that the objects created using Classes are collected by Garbage collector, but it cannot be collected by GC if it is being created using struct

I know that structures uses stack and classes uses heap.

But, I guess GC never collects unmanaged codes only. So does that mean that the Structure types are unmanaged code. (I don’t think so).

OR is it that the GC take care of Heap only and not Stack?

If yes, then what about int data type. int is struct not class. So if we defined the object of type int, isn’t it managed by GC?

  • 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-06-09T00:35:49+00:00Added an answer on June 9, 2026 at 12:35 am

    The GC will collect any managed objects (and Structures are managed objects) if they cannot be accessed from a GC root.

    but it cannot be collected by GC, if it is being created using struct.

    What you were told is incorrect. It doesn’t matter how a managed object was created – if there are no references to it anymore, it will end up being collected.

    OR is that means the GC take care of Heap only not Stack?

    The GC takes care of the object graph – if objects are reachable by any of the GC roots, they will not be collected, if they are not, they will end up being collected. The Stack and Heap are not relevant.

    So if we defined the object of type int, isn’t it managed by GC?

    int (AKA System.Int32) is a managed object – a structure. If you declare an int field in a class and the class goed out of scope, the int will end up being collected by the GC, for example.


    As @leppie commented, in many situations, structures will get placed on the stack and when the stack is popped they will no longer exist – the GC, in such cases, is not involved (and doesn’t need to be).

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

Sidebar

Related Questions

Yesterday I had a few question about OO and classes in PHP here but
So yesterday we had a table that has an auto_increment PK for a smallint
I had this code working yesterday, but it seems like I edited it a
Yesterday I had problems with another boost functions but luckily you guys helped me
After posting a question yesterday I thought I had this cleared up but I'm
Yesterday I had a team leader of another team say that they took a
I had my code work fine yesterday, but today I can no longer get
I had put an question in StackOverflow yesterday but could not get the answer.
Yesterday I had an interview where the interviewer asked me about the storage classes
This is a continuation from a question that I had yesterday. I am trying

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.