I have this small structure that i use only to manage the contents of some comboboxes instead of a database, by reading from an XML file, but each time the index of another combobox is changed, the contents of the whole combobox gets cleared and refilled, obviously with new structure objects.
At doing this, i know i am removing all the structures from the comboboxes item's list, but the objects are not disposed, as far as i know.
I've created an structure because I read that a structure is good when you are going to instantiate too many small classes, because they are faster at stacking in memory...
In any case im not very familiarized with the structures and also i was trying the new knowledge, so i want to know both things:
Should I make the structure disposable or the GC does it automatically, and also; is this a good use for a structure, or is better to make it a class?
Friend Structure FileRef
Private _FileName, _Extension, _Path As String
Public Property Display As String
Public ReadOnly Property Path As String
Get
Return Me._Path
End Get
End Property
Public ReadOnly Property FileName As String
Get
Return Me._FileName
End Get
End Property
Public ReadOnly Property Extension As String
Get
Return Me._Extension
End Get
End Property
Public Sub New(ByVal path As String)
Me._Path = path
Me._Extension = System.IO.Path.GetExtension(Me._Path)
Me._FileName = System.IO.Path.GetFileName(Me._Path)
End Sub
Public Sub New(ByVal path As String, ByVal AutoDisplay As Boolean)
Me._Path = path
Me._Extension = System.IO.Path.GetExtension(Me._Path)
Me._FileName = System.IO.Path.GetFileName(Me._Path)
If AutoDisplay = True Then _
Me.Display = System.IO.Path.GetFileNameWithoutExtension(Me.Path)
End Sub
Public Sub New(ByVal path As String, ByVal display As String)
Me._Path = path
Me._Extension = System.IO.Path.GetExtension(Me._Path)
Me._FileName = System.IO.Path.GetFileName(Me._Path)
Me.Display = display
End Sub
Public Overrides Function ToString() As String
If Me.Display = Nothing Then Return Me.Path Else Return Me.Display
End Function
End Structure
I use it like this:
Private Sub cboCollection_SelectedIndexChanged(sender As Object, e As EventArgs) _
Handles cboCollection.SelectedIndexChanged
If cboCollection.SelectedIndex >= 0 Then
Dim SelItem As FileRef = DirectCast _
(cboCollection.SelectedItem, FileRef)
cboCollection.Items.Clear()
cboImage.SelectedIndex = -1
Using fs As New FileStream(SelItem.Path,_
FileMode.Open, FileAccess.Read, FileShare.Read)
Using xmlR As XmlReader = XmlReader.Create(fs)
Try
Catch ex As Exception
End Try
End Using
End Using
End If
End Sub
Thanks in advance and sorry if i had bad english.
PS. I wrote in VisualBasic but answers in C# are also very welcome.