In .net, the unmanaged resources like file handles, database connections, etc... can be deleted or freed at any time through the dispose method. But there is no way for the determinstic deletion of the managed objects. The managed objects are deleted by the garbage collector only when it runs. we can not predict when the GC runs. It runs when the generations are full based on the generation algorithm. The main problem of not having the deterministic deletion of the managed objects to which there are no further references existing in the program is that they occupy the main memory unnecessarily till the time the GC runs even though there is no use of them.
The memory management job has been taken from the developer and given to the GC to get rid of 2 problems which troubled the unmanaged c++ programmers a lot. They are 1. Memory leaks and 2. Access violations.
The reason behind not providing the deterministic deletion of the managed objects to the developer is to avoid access violations. That is good and safe. But it causes the above problem. It would be better if there is any other approach to avoid the access vioaltions while providing a way to the developers to delete the managed objects.
Loading
VulpesPosted Apr 15, 2011, 5:28 AM
Srinivas SripathiPosted Apr 15, 2011, 5:00 AM
VulpesPosted Apr 15, 2011, 4:45 AM
However, there are only a few occasions when you need to because garbage collections occur quite frequently and are not usually noticeable. One such occasion is when you're writing a real-time application and you don't want the GC to kick in whilst you're doing a critical operation. You can then call GC.Collect() just before doing the critical operation.
No system is perfect but I've been using .NET now for 10 years and have never found automatic GC to be a problem. It allows me to concentrate on the logic of the program rather than the system plumbing and is certainly a lot better than the vagaries of reference counting in COM programming.
Sam HobbsPosted Apr 15, 2011, 4:43 AM
Srinivas SripathiPosted Apr 15, 2011, 4:30 AM
Sam HobbsPosted Apr 15, 2011, 3:18 AM