C# Programming - .NET Framework - Discussion
Discussion Forum : .NET Framework - General Questions (Q.No. 7)
7.
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.
Discussion:
7 comments Page 1 of 1.
Strider said:
8 years ago
I am not so sure about 2. A memory leak can also occur when your program still references unused objects in the heap, due to issues in the code. How will the GC avoid this kind of a leak?
Sateesh said:
9 years ago
Nice explanation @Karthikeyan_R.
Naman said:
1 decade ago
GC clears memory used by unused managed code, not the memory used by unmanaged code. Definitely, option 4 and 5 are not done by GC. Moreover, GC automatically frees heap memory. (Hence, next time while using collection you can choose to use Lis t<T> and Dictionary< key,value> instead of ArrayList and HashTable.) So, option 1 is definitely not done by GC. The rest of the options are the tasks done by GC. Hence, option C.
Karthikeyan_r said:
1 decade ago
1. Freeing memory on the stack.
An stack cannot be removed directly by the garbage collector.
The items of stack are referred by the object nd through removing object only we can remove stack items.
So option 1 can't be done by g. C.
2. Avoiding memory leaks.
Yes, of course g. C always checks for an memory leaks in its progress.
Memory leaks are nothing but, for eg. you are declaring an variable as in an memory location but you are making it to hold values beyond the limit its limit. So arises the case of memory leaks!
Option 2 is done by g. C.
3. Freeing memory occupied by unreferenced objects.
Option 3 is common because its the the role of g. C to deallocate objects. So, option 3 also is done by g. C.
4. Closing unclosed database collections.
5. Closing unclosed files.
By default g. C can call only dispose () which calls back finally ().
So g. C an close unclosed files & database collections by using over-riding concept of dispose (). But it can't be used without over-riding.
So option 4, 5 also fails in this case.
On considering these facts the answer will be: [c]. 1, 4, 5.
An stack cannot be removed directly by the garbage collector.
The items of stack are referred by the object nd through removing object only we can remove stack items.
So option 1 can't be done by g. C.
2. Avoiding memory leaks.
Yes, of course g. C always checks for an memory leaks in its progress.
Memory leaks are nothing but, for eg. you are declaring an variable as in an memory location but you are making it to hold values beyond the limit its limit. So arises the case of memory leaks!
Option 2 is done by g. C.
3. Freeing memory occupied by unreferenced objects.
Option 3 is common because its the the role of g. C to deallocate objects. So, option 3 also is done by g. C.
4. Closing unclosed database collections.
5. Closing unclosed files.
By default g. C can call only dispose () which calls back finally ().
So g. C an close unclosed files & database collections by using over-riding concept of dispose (). But it can't be used without over-riding.
So option 4, 5 also fails in this case.
On considering these facts the answer will be: [c]. 1, 4, 5.
Surekha kulkarni . said:
1 decade ago
But what is meant by avoiding memory leaks?can anyone explain me.
Saranya said:
1 decade ago
Is a process that automatically frees the memory of objects that are no more in use.
So the answer 3 is correct.
So the answer 3 is correct.
S.Malathi said:
1 decade ago
Garbage collector is used for deallocate memory for unrefrenced objects and complete object. Ans 3 is correct, . 3 choices has 3 part except c choce.
Post your comments here:
Quick links
Quantitative Aptitude
Verbal (English)
Reasoning
Programming
Interview
Placement Papers