Garbage collection (GC) is a form of automatic memory management. The garbage collector attempts to reclaim memory used by objects that will never be accessed or mutated again by the application.
Garbage collection essentially is a 2-step process:
- It determines which objects in a program will not be accessed in the future,
- And then reclaims the resources used by these objects.
Automatic memory management can eliminate common problems, such as forgetting to free an object and causing a memory leak, or attempting to access memory for an object that has already been freed. It aids programmers in their efforts to make programs more stable, because it prevents several runtime errors. E.g. it prevents dangling pointer errors, where a reference to a de-allocated object is used.
|
|
No comments:
Post a Comment