When I read the DOTNET document with a good mood, dispose entered my sight with disgust.
First, I realized that some objects must be manually called with dispose, which is not a joke. The requirements mentioned in this document are serious. For example, sqlconnection, although you do not manually call dispose or close, in some cases, because the system will automatically call those in some cases; but in other cases, if you do not call dispose or close, the connection pool will be quickly cleaned up.
Secondly, dispose makes me very frustrated that it is not easier to control than the heap memory pointer of C ++. We have just determined that dispose (or similar alternative method) must be manually called for some objects, otherwise it is prone to problems. OK. Next, I found that if we forget to release somewhere, we can hardly determine which damn place we forgot to release, it can be exactly where the resources are exhausted; and until the resources are exhausted, you can hardly find this problem; and when the resources are exhausted, you have no way to detect when resources are exhausted. If such a problem is found in a large project module, some people will go crazy. Therefore, some people say that DOTNET is not suitable for large projects, which is somewhat reasonable. In contrast, although the heap memory pointer of C ++ needs to be released, we can at least easily detect memory leaks.