Questions tagged [garbage-collection]

Questions about the automatic memory management used by virtual machines to ensure that unused memory/objects is released and reused.

wiki describes garbage collection as :

In computer science, garbage collection (GC) is a form of automatic memory management. The garbage collector, or just collector, attempts to reclaim garbage, or memory occupied by objects that are no longer in use by the program.

111 questions
68
votes
16 answers

Why do languages such as C and C++ not have garbage collection, while Java does?

Well, I know that there are things like malloc/free for C, and new/using-a-destructor for memory management in C++, but I was wondering why there aren't "new updates" to these languages that allow the user to have the option to manually manage…
Dark Templar
  • 6,303
  • 16
  • 47
  • 47
18
votes
1 answer

When a garbage collector compacts objects in the heap, does it change the references on the stack?

This seems like a simple question, but after a lot of reading on the subject, I still haven't found a definitive answer (perhaps because it is so simple). My question is this: when a garbage collector compacts objects in the heap, how are the…
todorojo
  • 281
13
votes
10 answers

Is garbage collection necessary?

Do any languages really need garbage collection? Is there not a way to figure out when a object should be destroyed? I haven't had leaks in C++ and i dont use smart pointers or reference counters or anything special. I confirm this by attaching…
user2528
8
votes
2 answers

How does a concurrent garbage collector deal with variables?

Let's say it is a concurrent mark-and-sweep garbage collector. When such GC handles constant pointers it just walks through them (starting from roots), and marks every encountered data block. Then sweeps everything unmarked. A client code should…
lorus
  • 497
  • 1
  • 3
  • 10
5
votes
2 answers

How a Garbage Collector follows pointers to discover live objects

I have read through A tour of V8: Garbage Collection and am stuck on this part: Distinguishing pointers and data on the heap is the first problem any garbage collector needs to solve. The GC needs to follow pointers in order to discover live…
Lance
  • 2,587
  • 19
  • 35
2
votes
1 answer

Is it appropriate to try to control the order of finalization?

I'm writing a class which is roughly analogous to a CancellationToken, except it has a third state for "never going to be cancelled". At the moment I'm trying to decide what to do if the 'source' of the token is garbage collected without ever being…
1
vote
1 answer

How is the “grey list” implemented in modern garbage collectors?

In the Wikipedia article for “tracing garbage collection”, the following claim is made: ...most modern tracing garbage collectors implement some variant of the tri-color marking abstraction In this abstraction, objects are grouped into three sets:…
Ricky Stewart
  • 457
  • 2
  • 7