Deterministic deletion of the managed object

Apr 15 2011 2:44 AM
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.

Answers (6)