Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

Memory Leaks

ramesh
2005-11-08
2013-01-13
  • ramesh
    ramesh
    2005-11-08

    Hi,

    We are using the CeWolf tool and JFree Charts in JSP page , the funtionality is every 60 seconds the Jsp pages refreshes automatically.

    We have verified leakages from JProbe Memory Debugger ,

    We are using cewolf images for creating charts.
    Please find the code in the jsp

    <logic:equal name="data" property="displayMemoryData" value='<%=DashboardConstants.ON%>'>
    <TD>
    <cewolf:chart
    id="memoryMeterChart"
    type="meter">
    <cewolf:colorpaint color='#F0F0F0'/>
    <cewolf:data>
    <cewolf:producer id="memorySummary" />
    </cewolf:data>
    <cewolf:chartpostprocessor id="memorySummary">
    </cewolf:chartpostprocessor>
    </cewolf:chart>
    <cewolf:img chartid="memoryMeterChart" renderer="/cewolf" width='<%=data.getImageWidth()%>' height='<%=data.getImageHeight()%>' border="1" onclick="return doImageClick('system');"/>
    </TD>
    </logic:equal>

    As per the JProbe Memory Debugger MeterPlot and JFreeChart classes objects are  growing in every refresh of JSP page..

    Process chart code:

    MeterPlot plot = (MeterPlot) ((JFreeChart) chart).getPlot();

    Number value = ((DefaultValueDataset)plot.getDataset()).getValue();
    int intValue = value.intValue();

    //update the niddle color of the tachometer based on the value
    if (intValue < minWarn)
    plot.setNeedlePaint(java.awt.Color.GREEN);
    else if (intValue < minCrit)
    plot.setNeedlePaint(java.awt.Color.YELLOW);
    else
    plot.setNeedlePaint(java.awt.Color.RED);

    plot.setDialBackgroundPaint(java.awt.Color.DARK_GRAY);
    plot.setValuePaint(java.awt.Color.WHITE);

    After some time we are getting OutofMemoryError.
    Can you please let me know If you have any idea why MeterPlot and JFreeChart classes objects are growing .

    Please let me know how can we delete chart before refresheing the JSP page.

    Thanks,
    Ramesh

     
    • Brian Fox
      Brian Fox
      2005-11-08

      What storage object are you using in your web.xml?

       
    • ramesh
      ramesh
      2005-11-08

      Hi Brian Fox ,

      Here is the code in the web.xml regarding storage object.

      <init-param>
            <param-name>storage</param-name>
            <param-value>de.laures.cewolf.storage.TransientSessionStorage</param-value>
          </init-param>

       
      • Brian Fox
        Brian Fox
        2005-11-08

        Ok, the problem is that this storage object keeps putting the objects into the session and never clears them. It's meant for transient sessions. You can use LongTermSessionStorage instead. This will create a single object with a thread that will time out the objects. This is documented at: https://sourceforge.net/tracker/?func=detail&atid=483599&aid=1002248&group_id=57282 or search for bug id 1002248

        This class will create 1 thread per session so for large amounts of sessions, this might not be the best solution. I'll be fixing that in the near future.

         
    • ramesh
      ramesh
      2005-11-09

      Hi ,

      Now we have made storage type to LongTermSessionStorage

      <init-param>
      <param-name>storage</param-name>
      <param-value>de.laures.cewolf.storage.LongTermSessionStorage </param-value>
      </init-param>
      Also we have added the timeout value to 30 in img tag.
      Now the garbage collection is happening , but we see in the JProbeMemoryDebugger JFreeChart and MeterPlot classes objects are still growing.

      Our application refreshes every 30 sec and it recreates images for every refresh.

      Please let me know if you have any thought  on how we can make JFreeChart and MeterPlot classes for the garbage collection.

      This is our post processing the chart :

      public void processChart(Object chart, Map params) {
            MeterPlot plot = (MeterPlot) ((JFreeChart) chart).getPlot();
            //override the default insets for the plot
            Insets defaultInsets = plot.DEFAULT_INSETS;
            plot.setInsets(new Insets(defaultInsets.top+25,defaultInsets.left+25,defaultInsets.bottom+25,defaultInsets.right+25));

            ((JFreeChart)chart).addSubtitle(new TextTitle(messages.getMessage("memoryUtilization.text")));

            DashboardPreferencesForm preferences = DashboardUtilities.getDashboardPreferences(getSession(), getRequest());

            double min = 0;
            double max = 100;
            double minCrit = Integer.parseInt(preferences.getMemoryCritical());
            double maxCrit = max;
            double minWarn = Integer.parseInt(preferences.getMemoryWarning());
            double maxWarn = minCrit;
            double maxNorm = minCrit;
            double minNorm = min;

            plot.setRange(new Range(min, max));
            plot.setNormalRange(new Range(minNorm, maxNorm));
            plot.setWarningRange(new Range(minWarn, maxWarn));
            plot.setCriticalRange(new Range(minCrit, maxCrit));
            plot.setUnits("%");

            Number value = ((DefaultValueDataset)plot.getDataset()).getValue();
            int intValue = value.intValue();

            //update the niddle color of the tachometer based on the value
             if (intValue < minWarn)
               plot.setNeedlePaint(java.awt.Color.GREEN);
             else if (intValue < minCrit)
               plot.setNeedlePaint(java.awt.Color.YELLOW);
             else
               plot.setNeedlePaint(java.awt.Color.RED);

             plot.setDialBackgroundPaint(java.awt.Color.DARK_GRAY);
             plot.setValuePaint(java.awt.Color.WHITE);
         }

      Thanks
      Ramesh

       
    • ramesh
      ramesh
      2005-11-09

      Hi,

      Thanks for the solution , Now we are using LongTermSessionStorage , Now it seems to be releasing chart id's . But our application refreshes  page for every 60 sec , we keep on create chart images for every refresh . As you mentioned 1 thread will be createated  for each session , does this mean these threads will exist for ever or will die after the time out period as you mentioned.

      Thanks
      Ramesh

       
      • Brian Fox
        Brian Fox
        2005-11-09

        When there are no more objects waiting to be deleted, the thread will die. If objects are added later, the thread will be recreated. When the session is invalidated or times out, the whole object is evicted and everything goes away.

         
        • ramesh
          ramesh
          2005-11-09

          Hi ,
          After making the storage class to LongTermSessionStorage , we are running the application in windows machine , garbage collection is happening properly . When we try to run on UNIX (HP-UX) the size of the java process keep on growing.Do we have any thing in the configaration that needs to be taken care on the UNIX side.
          Please let us know if you have any idea on this.

          Thanks,
          Ramesh

           
    • Brian Fox
      Brian Fox
      2005-11-09

      I should mention that the reason I personally needed to have some charts live for longer than just displaying them is this:
      When a user copies an image from the browser, the browser often puts just the url into the buffer. If the image has timed out and they try to paste into, say, word, then they get an image saying the chart has timed out. If you think users might do this, then maybe you want to let the charts live long enough for a typical cut and subequent paste. (even if new ones are being generated)

       
    • ramesh
      ramesh
      2005-11-09

      Hi

      In our application user will not do copy , cut , paste the images .

      After making the storage class to LongTermSessionStorage , we are running the application in windows machine , garbage collection is happening properly . When we try to run on UNIX (HP-UX) the size of the java process keep on growing.Do we have any thing in the configaration that needs to be taken care on the UNIX side.
      Please let us know if you have any idea on this.

      Thanks
      Ramesh

       
    • ramesh
      ramesh
      2005-11-09

      Hi,
      Are you aware of the probelm discussed in the JFreeChart forum, Here is the link for that

      http://www.jfree.org/phpBB2/viewtopic.php?t=15017

      Please let us know If we can do in our code as work around.

      Thanks,
      Ramesh