不使用 Dispose() ,也会自动回收的。不用担心这

解决方案 »

  1.   

    那句柄要如何释放啊,我在测试时有较大数量的控件添加,20分钟左右会报错
    </StackTrace><ExceptionString>System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---&amp;gt; System.ComponentModel.Win32Exception: Error creating window handle.
       at System.Windows.Forms.NativeWindow.CreateHandle(CreateParams cp)
       at System.Windows.Forms.Control.CreateHandle()
       at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
       at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
       at System.Windows.Forms.Control.CreateControl()
       at System.Windows.Forms.Control.ControlCollection.Add(Control value)
      

  2.   

    那其中的handle和事件用不用注销掉啊
      

  3.   

    事件不用管,控件都没了,属性和事件也就没了
    handle又是什么?
      

  4.   

    Dispose是用来释放非托管资源的。你只要确定断开其他地方对你想要释放对象的调用,其他就交给gc来回收。事件的问题,如果这个控件绑定了外部控件/对象的代码,也是会导致无法释放的。(.NET GC不是很确定,Silverlight GC不会释放)所以此类事件你需要手工-=去掉绑定的外部方法。