【发布时间】:2012-08-27 09:28:51
【问题描述】:
我正在考虑处置资源,并在不同的处理方式上搞混了。
我刚刚发现,在使用 ShowDialog() 显示的表单上使用 Close() 只是实际上隐藏了它,并没有完全杀死它,可以这么说。虽然这对我目前想要的东西很有用,但我现在担心其他地方的内存泄漏。
使用 ShowDialog() 后,我应该总是在表单上调用 Dispose() 还是使用 Using 块?有区别吗?或者当退出创建子程序时表单会被自动处理吗?例如,我典型的简单用法之一:
Private Sub btnEdit_Click(sender As System.Object, e As System.EventArgs) Handles btnEdit.Click
Dim frm As New frmSomething()
frm.ShowDialog()
'frm is exited by clicking the X or using Close()
'At this point, frm is still in memory. Is it automatically disposed of
'after the End Sub here, or should I do frm.Dispose() ?
End Sub
【问题讨论】:
标签: vb.net garbage-collection dispose