请看一下我从MSDN 网站获取的以下代码:
Sub Page_Load(sender As Object, e As EventArgs)
' Generate rows and cells.
Dim numrows As Integer = 3
Dim numcells As Integer = 2
Dim j As Integer
For j = 0 To numrows - 1
Dim r As New TableRow()
Dim i As Integer
For i = 0 To numcells - 1
Dim c As New TableCell()
c.Controls.Add(New LiteralControl("row " & j.ToString() & ", cell " & i.ToString()))
r.Cells.Add(c)
Next i
Table1.Rows.Add(r)
Next j
End Sub 'Page_Load
每行都有一个新的 TableRow 实例,并为每个表格单元格创建了一个新的 TableCell 实例。我对此有两个问题:
- 这些实例是如何被销毁的?即
c = Nothing
。肯定有内存泄漏? Table 类如何知道
TableRow
and的实例在哪里TableCell
?我问的原因是因为您似乎无法TableCell
为多个表格单元格和TableRow
多个表格行重用实例,即您不能执行以下操作:Dim objTable As New Table Dim objTableRow As New TableRow Dim objTableCell As New TableCell objTableCell.Text = "Test Row 1 Cell 1" objTableRow.Cells.Add(objTableCell) objTableCell.Text = "Test Row 1 Cell 2" objTableRow.Cells.Add(objTableCell) objTable.Rows.Add(objTableRow) objTableCell.Text = "Test Row 2 Cell 1" objTableRow.Cells.Add(objTableCell) objTableCell.Text = "Test Row 2 Cell 2" objTableRow.Cells.Add(objTableCell) objTable.Rows.Add(objTableRow) objTableCell.Text = "Test Row 3 Cell 1" objTableRow.Cells.Add(objTableCell) objTableCell.Text = "Test Row 3 Cell 2" objTableRow.Cells.Add(objTableCell) objTable.Rows.Add(objTableRow)