Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

If i create a small class:

 

Public Class XMLNode1
   Private xmlHeader As String
   Private xmlValue As String

   Public Sub New()
       xmlHeader = Nothing
       xmlValue = Nothing
   End Sub
   Public Sub New(ByVal head As String, ByVal val As String)
       Me.propHead = head
       Me.propVal = val
   End Sub

   Public Property propHead()
       Get
           Return xmlHeader
       End Get
       Set(ByVal value)
           xmlHeader = value.ToString
       End Set
   End Property
   Public Property propVal()
       Get
           Return xmlValue
       End Get
       Set(ByVal value)
           xmlValue = value.ToString
       End Set
   End Property


End Class

 

How should i go about writing a disposal method for it?

Also, my idea of disposing a class is releasing all th eobject that class uses...Is that correct?

 

 

Please help :confused:

  • Administrators
Posted

Unless your class deals with non-managed resources (or .net wrappers around them such as file streams or data base connections) then you don't need to worry about disposing of resources. If the code posted is the entire class then as it only contains two strings there isn't any need to worry about disposing of it's resources.

 

Just as a side note though you might want to give the two properties a valid data type - as it stands the are just going to be treated as object rather than strings.

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

Posted

I do have another class that uses an arraylist,xml reader, sql adapter, and sql connection.

 

I read about including a dispose method , but im not sure how to implement this. I guess i could just call each objects dispose method, but im curious as to add the disposal methods to my class.

  • Administrators
Posted

If you are only using the data adapter to access the db then just let it manage the connection for you, i.e. don't open or close it yourself.

 

If you are using the connection directly (DataReader or executing commands directly) then just get into the habit of opening the connection as you need it and closing it as soon as you are finished (preferably with a try ... finally or a using block).

 

Again either of these methods mean you shouldn't need to deal with the disposal of objects directly. If you are interested in how to write a dispose method then either http://msdn2.microsoft.com/en-us/library/system.idisposable.aspx or http://msdn.microsoft.com/msdnmag/issues/07/07/CLRInsideOut/default.aspx are worth a read.

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...