就本例而言,我发现只须添加一个窗体,将它删除,然后强制执行垃圾收集,结果就会导致与被删除窗体相关联的许多类实例仍然处于活动状态。
For this example, I found that simply adding a form, deleting the form, and then forcing a garbage collection resulted in many class instances associated with the deleted form to still be alive.
用另外一个更合适的控件来完全替换当前控件可不容易,你需要删除这个控件,然后将一个新控件拖入窗体并重新配置它。
Completely replacing one control with another more relevant control is not as simple; you will need to delete an existing control, drop a new one on the form, and reconfigure it.
当作了这些修改以后,我使用调试器证实:当执行相同的测试案例时,与被删除的窗体相关联的对象计数减小。
After I made these code changes, I used the debugger to verify that the object count associated with the deleted form decreased when the same test case was executed.
应用推荐