memory leaks - C# disposing IDisposable -


Can anyone say that if you do not have a dispose something IDisposable If not unit ( or direct dissection call) using ?

Is it always a memory leak and if yes, C # memory leaks similar to the C ++ memory leak Is where they can easily crash or C # is sandbox safe from this perspective?

Thank you.

It depends entirely on the object in question

There are five reasons That can apply any object to IDisposable :

  1. This is the owner of the original resources. If so, then call it should dissect in its final form, so it happens that if you forget to dispose of it then it is that the need for native resources Over time is old. Br> If you create so many objects at once and do not settle them, then you can be out of basic resources.

  2. It is the owner of managed objects that are disposable.
    The objects which are owned by them will fall into any of these categories; See related category.

  3. There is a long-term reference to yourself that will not be naturally free (for example, it handles a stable event) The settlement method will explain this context (for example, uncheck the event handler) - If so, then dissection will not be called, it will be finalized forever.

  4. This handles a disposable base class, such as stream or component , but it really needs to be disposed of (For example, memorystream ) If so, then dissection is not calling, as long as the class does not change in the future.

  5. It does some action in its dissection method, which is used by people by using the statement statement (for example, Code> should be used (HTML.BeginForm () {...} ) If this is the case, by not disabling the object, there will be a loss to its entire purpose, which is to take action.

Comments