The more I push in the C # and the GC, I find more things, I'm not sure about this I always thought Dispos and related finals are only necessary when there are some unmanaged resources in my class.
But I have many opportunities where there are only native C # classes where this is not quite clear to me. I need disposal and related final additives. For example, when the event handler is attached to my event .
Do I need to remove event-handlers when I call them on a bus? Besides, I was told that if the event handler is still connected then the objects will not be collected. If this is the case then GC is compromised in some way.
Is it possible that when and how do I need to execute and apply lastly?
Actually I have more questions about this, but perhaps the answer to this question can help me further. Dealt with and finalize:
If you have any The area that is one (or some other kind of unmanaged resource, but IntPtr
is the most common) and this is the responsibility of your classes that you need to implement in order to clear that resource. . In that final, you should also remove any resources from IntPtr
points. If you do not have any interpreter, then the class you are holding should be finalized and it will be applicable to IDisposeable
(see the next section)
If you have The field is applied to your class and your class is responsible for cleaning after that object, your class should also implement IDisposable
and you should resolve that method which you Dispose ()
should call the object.
For event handlers, this is a matter of personal choice. You can, but it is important only if you do or not.
Unless you expect the publisher of this program to exit the customer, there is no reason to remove the event handler ...
I am not personally, but I know some people who do, if you want to do this, then the process is setting the event handler to null
in your settlement method only.
Public Sealed Class Example: IDisposable {public event handler MyAvent; Remove public null () {MyEvent = null; Edit}: And a good point is that: You do not have required in the final form, if you have an unmanaged resource For which it will need to be finalized. Wrap the wrapper to handle the final form for you. Once you do this, the object becomes just another normal IDisposable
, then you will get your < Code> has to be kept in mind. Wizard ()
method
No comments:
Post a Comment