Announcement

Collapse
No announcement yet.

Stringbuilder function increase ram

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Stringbuilder function increase ram

    Hi, I have notice that stringbuilder are taking more and more memory when the webpage are loading or reloading. The plugin starts with about 50Mb ram and when the plugin's webpage loads first time it goes up to 90mb and then growing slowly up to 200mb. I'm closing/clean all variables, arrays & stringbuilder when they have done what they should but the memory reservation still remains. Any suggestions?
    Attached Files
    Please excuse any spelling and grammatical errors I may make.
    --
    Tasker Plugin / Speech Droid
    Tonlof | Sweden

  • #2
    Are you using StringBuilder.Append() instead of concatenating strings?

    For example:

    PHP Code:
    Dim sbData As StringBuilder = New StringBuilder
    sbData
    .Append("This is the right way")
    sbData.Append("Do not " "use" " concatenation.")

    ''always clear when done...
    sbData.Clear()
    ''flag it for GC
    sbData 
    Nothing 
    If you have a Try/Catch and have an error, your Finally clause needs to handle cleanup of all variables.
    HS3Pro Running on a Raspberry Pi3
    64 Z-Wave Nodes, 168 Events, 280 Devices
    UPB modules via OMNI plugin/panel
    Plugins: Z-Wave, BLRF, OMNI, HSTouch, weatherXML, EasyTrigger
    HSTouch Clients: 3 Android, 1 Joggler

    Comment


    • #3
      Originally posted by rmasonjr View Post
      Are you using StringBuilder.Append() instead of concatenating strings?

      For example:

      PHP Code:
      Dim sbData As StringBuilder = New StringBuilder
      sbData
      .Append("This is the right way")
      sbData.Append("Do not " "use" " concatenation.")

      ''always clear when done...
      sbData.Clear()
      ''flag it for GC
      sbData 
      Nothing 
      If you have a Try/Catch and have an error, your Finally clause needs to handle cleanup of all variables.
      Thanks rmasonjr, I will add clean up in Catch, is it better to use Append to all text & variables without using & to add variables to the stringbuilder.
      Please excuse any spelling and grammatical errors I may make.
      --
      Tasker Plugin / Speech Droid
      Tonlof | Sweden

      Comment


      • #4
        Originally posted by tonlof View Post
        Thanks rmasonjr, I will add clean up in Catch, is it better to use Append to all text & variables without using & to add variables to the stringbuilder.
        Yep - from what my developers are telling me, it is better to load up your variables outside of the stringbuilder and just .Append it.

        Note that setting sbData = Nothing will flag that object for garbage collection. That may not happen immediately; it depends on when it runs.
        HS3Pro Running on a Raspberry Pi3
        64 Z-Wave Nodes, 168 Events, 280 Devices
        UPB modules via OMNI plugin/panel
        Plugins: Z-Wave, BLRF, OMNI, HSTouch, weatherXML, EasyTrigger
        HSTouch Clients: 3 Android, 1 Joggler

        Comment


        • #5
          Originally posted by rmasonjr View Post
          Yep - from what my developers are telling me, it is better to load up your variables outside of the stringbuilder and just .Append it.

          Note that setting sbData = Nothing will flag that object for garbage collection. That may not happen immediately; it depends on when it runs.
          I have isolate the memory usage when adding below loop to tab.tabContent = data.ToString (If this line is commengt out the memory does not increase.)
          PHP Code:
          ... 
          For 
          Each dv In col
                              
          If dv Is Nothing Then Continue For
                              
          Dim str_dtr As String ""
                              
          Dim str_dsr As String ""
                              
          Dim str_dvr As String ""

                              
          Dim str_dtc As String ""
                              
          Dim str_dsc As String ""
                              
          Dim str_dvc As String ""

                              
          Dim str_dta As String ""
                              
          Dim str_dsa As String ""
                              
          Dim str_dva As String ""

                              
          Dim dtr As New clsJQuery.jqToolTip(hs.ReplaceVariables("$$DTR:" dv.Ref(Nothing) & ":"))
                              
          Dim dsr As New clsJQuery.jqToolTip(hs.ReplaceVariables("$$DSR:" dv.Ref(Nothing) & ":"))
                              
          Dim dvr As New clsJQuery.jqToolTip(hs.ReplaceVariables("$$DVR:" dv.Ref(Nothing) & ":"))

                              
          str_dtr dtr.build.ToString " " "$$DTR:" dv.Ref(Nothing) & ":"
                              
          str_dsr dsr.build.ToString " " "$$DSR:" dv.Ref(Nothing) & ":"
                              
          str_dvr dvr.build.ToString " " "$$DVR:" dv.Ref(Nothing) & ":"

                              
          If dv.Code(Nothing).Length 0 Then
                                  Dim dtc 
          As New clsJQuery.jqToolTip(hs.ReplaceVariables("$$DTC:" dv.Code(Nothing) & ":"))
                                  
          Dim dsc As New clsJQuery.jqToolTip(hs.ReplaceVariables("$$DSC:" dv.Code(Nothing) & ":"))
                                  
          Dim dvc As New clsJQuery.jqToolTip(hs.ReplaceVariables("$$DVC:" dv.Code(Nothing) & ":"))

                                  
          str_dtc dtc.build.ToString " " "$$DTC:" dv.Code(Nothing) & ":"
                                  
          str_dsc dsc.build.ToString " " "$$DSC:" dv.Code(Nothing) & ":"
                                  
          str_dvc dvc.build.ToString " " "$$DVC:" dv.Code(Nothing) & ":"
                              
          Else
                                  
          str_dtc ""
                                  
          str_dsc ""
                                  
          str_dvc ""
                              
          End If

                              
          Dim address As String dv.Address(Nothing)

                              If 
          dv.Address(Nothing).Length And address.Contains(" ") = False Then
                                  Dim dta 
          As New clsJQuery.jqToolTip(hs.ReplaceVariables("$$DTA:" dv.Address(Nothing) & ":"))
                                  
          Dim dsa As New clsJQuery.jqToolTip(hs.ReplaceVariables("$$DSA:" dv.Address(Nothing) & ":"))
                                  
          Dim dva As New clsJQuery.jqToolTip(hs.ReplaceVariables("$$DVA:" dv.Address(Nothing) & ":"))

                                  
          str_dta dta.build.ToString " " "$$DTA:" dv.Address(Nothing) & ":"
                                  
          str_dsa dsa.build.ToString " " "$$DSA:" dv.Address(Nothing) & ":"
                                  
          str_dva dva.build.ToString " " "$$DVA:" dv.Address(Nothing) & ":"
                              
          Else
                                  
          str_dta ""
                                  
          str_dsa ""
                                  
          str_dva ""
                              
          End If

                              
          Dim str_address As String HTML_StartBold str_dta HTML_NewLine str_dsa HTML_NewLine str_dva HTML_EndBold
                              Dim str_ref 
          As String HTML_StartBold str_dtr HTML_NewLine str_dsr HTML_NewLine str_dvr HTML_EndBold
                              Dim str_code 
          As String HTML_StartBold str_dtc HTML_NewLine str_dsc HTML_NewLine str_dvc HTML_EndBold
                              data
          .Append(HTML_StartRow)
                              
          data.Append(HTML_StartCell("Devices"0HTML_Align.LEFTTrue))
                              
          data.Append(dv.Name(Nothing))
                              
          data.Append(HTML_EndCell HTML_StartCell("Devices"0HTML_Align.LEFTTrue))
                              
          data.Append(dv.Location(Nothing))
                              
          data.Append(HTML_EndCell HTML_StartCell("Devices"0HTML_Align.LEFTTrue))
                              
          data.Append(dv.Location2(Nothing))
                              
          data.Append(HTML_EndCell HTML_StartCell("Devices"0HTML_Align.LEFTTrue))
                              
          data.Append(HTML_StartBold "String" HTML_NewLine "Status" HTML_NewLine "Value" HTML_EndBold)
                              
          data.Append(HTML_EndCell HTML_StartCell("Devices"0HTML_Align.LEFTTrue))
                              
          data.Append(str_ref)
                              
          data.Append(HTML_EndCell HTML_StartCell("Devices"0HTML_Align.LEFTTrue))
                              
          data.Append(str_code)
                              
          data.Append(HTML_EndCell HTML_StartCell("Devices"0HTML_Align.LEFTTrue))
                              
          data.Append(str_address)
                              
          data.AppendLine(HTML_EndCell)
                              
          data.Append(HTML_EndRow)
                              
          data.Append(HTML_EndCell)
                              
          DT dv.DeviceType_Get(hs)
                          
          Next
                          data
          .Append(HTML_EndTable)
                          
                         
          'tab.tabContent = data.ToString 
          Please excuse any spelling and grammatical errors I may make.
          --
          Tasker Plugin / Speech Droid
          Tonlof | Sweden

          Comment


          • #6
            That actually looks very good to me. You're just putting a lot of data into the web page's tab content - nothing wrong with that. That may just be how it has to be. Note that I also use the clsJQuery tab UI in my plugins. I havent noticed memory issues, but the user really only goes to the config pages infrequently.
            HS3Pro Running on a Raspberry Pi3
            64 Z-Wave Nodes, 168 Events, 280 Devices
            UPB modules via OMNI plugin/panel
            Plugins: Z-Wave, BLRF, OMNI, HSTouch, weatherXML, EasyTrigger
            HSTouch Clients: 3 Android, 1 Joggler

            Comment


            • #7
              Originally posted by rmasonjr View Post
              That actually looks very good to me. You're just putting a lot of data into the web page's tab content - nothing wrong with that. That may just be how it has to be. Note that I also use the clsJQuery tab UI in my plugins. I havent noticed memory issues, but the user really only goes to the config pages infrequently.
              Thats true, I will check if the memory autorelease if I leave it in the debuger over the night.

              It may not be the stringbuilder that cause it but since it so big it may do anything with the tab function. Memory stays normal if I now disable
              jqtabs.tabs.Add(tab)

              tab.tabContent = data.ToString
              'jqtabs.tabs.Add(tab)
              tab = Nothing
              Please excuse any spelling and grammatical errors I may make.
              --
              Tasker Plugin / Speech Droid
              Tonlof | Sweden

              Comment

              Working...
              X