Jump to content
  • Advertisement
Sign in to follow this  
acddklr07

Questions about Garbage Collection

This topic is 4016 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello, I have recently started learning C#. I am using the book .Net Book Zero as the book to learn from since it is free. Right now I am on arrays and it has been talking about garbage collection a lot in this chapter and the last chapter. I already studied and been using C++ since December of last year, but I do not remember anything about garbage collection. At least in the sense C# does. I was wondering if that is one of the things that people choose C# over C++ as a recommendation as a first language? Also, I was wondering do C++ offer it too. I know what I learned so far it had never talked about garbage collection. For example, I remember one project I did when I had to basically tell the program to delete the information.(it was dealing with pointers and I believe memory on the heap....Sorry but I am not sure what word to use) Well I would thank anyone who takes the time to answer this. ~Carl J. Loucius

Share this post


Link to post
Share on other sites
Advertisement
C++ doesn't have garbage collection (although it may be optional in the future).

C# and Java do have garbage collection, so there is no need to manually delete things.

Share this post


Link to post
Share on other sites
Quote:
Original post by acddklr07
but I do not remember anything about garbage collection. At least in the sense C# does.


It's the virtual machine's job to do the collection, so you don't need to remember very much.

Quote:
I was wondering if that is one of the things that people choose C# over C++ as a recommendation as a first language?


One of many.

Quote:
Also, I was wondering do C++ offer it too.


There are libraries that offer it, but you have to be careful. The language is far too powerful (i.e. unsafe) for any kind of GC scheme to be 100% reliable.

Quote:
For example, I remember one project I did when I had to basically tell the program to delete the information.(it was dealing with pointers and I believe memory on the heap....Sorry but I am not sure what word to use)


'delete' is fine. One normally says "delete the pointer", but we really mean to deallocate the thing pointed at by the pointer. Technically, the allocations (made with 'new' in C++) come from the freestore; the heap is where malloc() allocates from (using the old-fashioned, only-there-for-backwards-compatibility C tools).

Normally, one simplifies the task of memory management in C++ by using the RAII idiom.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!