Which of the following jobs are NOT performed by Garbage Collector?
-
Freeing memory on the stack.
-
Avoiding memory leaks.
-
Freeing memory occupied by unreferenced objects.
-
Closing unclosed database collections.
-
Closing unclosed files.
Garbage Collector automatically manages heap memory by reclaiming objects that are no longer referenced, but it has specific limitations. It does NOT free stack memory (stack is automatically managed as methods return), does NOT close database connections (requires explicit closure or connection pooling), and does NOT close file handles (requires explicit closing). Option B is incorrect because GC cannot prevent all memory leaks - leaks can still occur with unintended references. Option C is something GC DOES perform (freeing unreferenced objects).
To answer this question, let's go through each option and determine whether it is performed by the Garbage Collector:
Option A) Freeing memory on the stack - This option is NOT performed by the Garbage Collector. The Garbage Collector is responsible for freeing memory occupied by objects on the heap, not on the stack.
Option B) Avoiding memory leaks - This option is performed by the Garbage Collector. The Garbage Collector identifies and collects memory that is no longer referenced, preventing memory leaks.
Option C) Freeing memory occupied by unreferenced objects - This option is performed by the Garbage Collector. The Garbage Collector identifies objects that are no longer referenced by the program and frees the memory occupied by those objects.
Option D) Closing unclosed database collections - This option is NOT performed by the Garbage Collector. Closing unclosed database collections is typically the responsibility of the programmer or the database management system, not the Garbage Collector.
Option E) Closing unclosed files - This option is NOT performed by the Garbage Collector. Closing unclosed files is typically the responsibility of the programmer or the operating system, not the Garbage Collector.
Therefore, the correct answer is A, D, and E. These options are not performed by the Garbage Collector.