使用轮询组件刷新时,Primefaces图表内存泄漏 [英] Primefaces chart memory leak when refreshing with poll component

查看:102
本文介绍了使用轮询组件刷新时,Primefaces图表内存泄漏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的页面上有10个图表,并且每1分钟使用 poll 组件刷新一次.但是一个小时后,我发现Firefox和Chrome获得了超过1 GB的内存,有时甚至崩溃了.

I have 10 charts in my page and I refresh them using poll component every 1 minute. But after one hour i see that firefox and chrome got more that 1 GB of memory and sometimes even firefox crashes.

这是素数图引起的内存泄漏吗?我该如何解决这个问题?

Is this a memory leak caused by primefaces chart? How can I solve the problem?

这是我的示例应用程序的源代码:

Here is the source code for my example application:

在此代码间隔中将其设置为3秒,以便更快地看到问题!

In this code interval is set to 3 seconds to see the problem sooner!

<h:body>

    <h:form id="timerForm">
        <p:poll interval="3" widgetVar="timer" update=":chartPanel" autoStart="true" /> 
    </h:form>
    <p:panelGrid columns="2" id="chartPanel">

        <p:lineChart id="chart1" value="#{chartController.model}"
                             legendPosition="nw" style="height:200px;width: 500px;" minY="0" />
        <p:lineChart id="chart2" value="#{chartController.model}"
                             legendPosition="nw" style="height:200px;width: 500px;" minY="0" />
        <p:lineChart id="chart3" value="#{chartController.model}"
                             legendPosition="nw" style="height:200px;width: 500px;" minY="0" />
        <p:lineChart id="chart4" value="#{chartController.model}"
                             legendPosition="nw" style="height:200px;width: 500px;" minY="0" />
        <p:lineChart id="chart5" value="#{chartController.model}"
                             legendPosition="nw" style="height:200px;width: 500px;" minY="0" />
        <p:lineChart id="chart6" value="#{chartController.model}"
                             legendPosition="nw" style="height:200px;width: 500px;" minY="0" />

    </p:panelGrid>

</h:body> 

这是bean:

@Named
@RequestScoped
public class ChartController {

static final Logger log = Logger.getLogger(ChartController.class.getName());

@PostConstruct
private void init() {
}

private ChartSeries getData(String label) {
    ChartSeries data = new ChartSeries();
    data.setLabel(label);
    for (int i = 1; i <= 20; i++) {
        data.set(i, Math.random() * 1000);
    }
    if (data.getData().isEmpty()) {
        data.set(0, 0);
    }
    log.log(Level.INFO, "Chart loaded for :{0}", label);
    return data;
}

public CartesianChartModel getModel() {
    CartesianChartModel chartModel = new CartesianChartModel();
    chartModel.addSeries(getData("Data 1"));
    chartModel.addSeries(getData("Data 2"));
    chartModel.addSeries(getData("Data 3"));
    return chartModel;
}
}

当我关闭浏览器时,它会完全释放内存.这是要下载的源代码:我已经上传了源代码,它是一个maven项目,只需下载并在IDE中打开它,然后将其部署在您的应用服务器中即可.

When I close the browser, it completely releases memory. And here is the source code to download: I have uploaded the source code, it's a maven project, just download it and open it in your IDE and deploy it in your app server.

https://dl.dropbox.com/s/secmuo7vjasdaue/chart-bug.zip?dl = 1

推荐答案

该组件在刷新之前不会破坏资源.我发现这是3.3.1版的错误,并已在3.4-SNAPSHOT中修复

The component does not destroy resources before refreshing. I found that this is a bug in version 3.3.1 and is fixed in 3.4-SNAPSHOT

这里是参考:

http://forum.primefaces.org/viewtopic.php?f=3&t=18286&hilit=图表+内存+泄漏

http://code.google.com/p/primefaces/issues/detail?id = 4183

这篇关于使用轮询组件刷新时,Primefaces图表内存泄漏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆