There is no class IDisposable
. There is an interface that serves to adopt a design pattern called Disposable or Disposable. You need to implement this standard properly, which is not easy, in your class for it to dispose of unmanaged resources. If you do not make manual release within this standard no release will occur, this standard only automates the release call that was made. If you don’t know how to do this don’t create a class that needs it, so avoid abstractions that require it. It’s hard and few people know how to do it right.
Note that I spoke about unmanaged resources. Managed memory doesn’t have to do anything, the Garbage Collector will do everything for you if you do not have some crazy code that prevents this, but it is even difficult to create a code that generates a problem like this.
If you are having memory problems the problem can be quite different from where it seems, it appears when everything is already clogged and not where the clogging begins.
Every time he gives one new
is creating a new object (an allocation is made), so it is not passing over anything. And in the list also you are not putting on top because always adding a new element and not using an existing one. If you want some to be discarded, and I don’t see why you would want that in this case, but it might just be because I don’t know the whole context, then you would have to make a logic that reuses the object instead of creating a new one.
Title referring to a doubt and in the context another doubt. Every new is a new instance so your list created objects are unique does not repeat no overwritten. The Idisposable interface is another implementation story of it is simple but there is the right time to do this should be studied and on the Microsoft website explains how it should be done.
– novic
Site https://docs.microsoft.com/pt-br/dotnet/api/system.idisposable?view=netframework-4.8 easy to understand
– novic