How to solve the problem of C # garbage collection
This article mainly explains "how to solve the problem of C# garbage collection". Interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to solve the C# garbage collection problem.
Here is the issue of C# garbage collection:
C # garbage collection is part of the .NET runtime. The garbage collector manages all managed objects, and all .NET languages that need managed data (including C #) are subject to the runtime's garbage collector. The C# garbage collector can determine the time to run garbage collection and automatically carry out C# garbage collection. However, one of the products of garbage collection is that there is no deterministic destruction of C# objects. Therefore, the object child has been destroyed, but it is not null, and an ObjectDisposedException exception is generated during access.
Method 1:
Modify the constructor of a sub-form
PublicChildForm () {/ /. This.Disposed+=newSystem.EventHandler (Form_Disposed)} / / then the handler function privatevoidForm_Disposed (objectsender,EventArgse) {Child=null;} of the event Form_Disposed
Method 2:
Override the OnClosed method of ChildForm
ProtectedvoidOnClosed (EventArgse) {base.OnClosed (e); child=null;} at this point, I believe you have a deeper understanding of "how to solve the C# garbage collection problem". You might as well do it in practice! Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!