This is an automated email from the ASF dual-hosted git repository. ovilia pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/echarts-handbook.git
The following commit(s) were added to refs/heads/master by this push: new 74a01e0 doc: add dispose in ssr document, close apache/echarts#19116 74a01e0 is described below commit 74a01e0bbc8b9ab01cb7a2e0df6b020b657215fe Author: Ovilia <zwl.s...@gmail.com> AuthorDate: Thu Nov 16 14:57:47 2023 +0800 doc: add dispose in ssr document, close apache/echarts#19116 --- contents/en/how-to/cross-platform/server.md | 12 +++++++++++- contents/zh/how-to/cross-platform/server.md | 12 +++++++++++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/contents/en/how-to/cross-platform/server.md b/contents/en/how-to/cross-platform/server.md index f045205..77d89d7 100644 --- a/contents/en/how-to/cross-platform/server.md +++ b/contents/en/how-to/cross-platform/server.md @@ -38,6 +38,10 @@ chart.setOption({ // Output a string const svgStr = chart.renderToSVGString(); + +// If chart is no longer useful, consider dispose it to release memory. +chart.dispose(); +chart = null; ``` The overall code structure is the almost same as in the browser, starting with `init` to initialise a chart example and then setting the configuration items for the chart via `setOption`. However, the parameters passed to `init` will be different from those used in the browser. @@ -112,11 +116,17 @@ chart.setOption({ //... }); +const buffer = renderChart().toBuffer('image/png'); + +// If chart is no longer useful, consider dispose it to release memory. +chart.dispose(); +chart = null; + // Output the PNG image via Response res.writeHead(200, { 'Content-Type': 'image/png' }); -res.write(renderChart().toBuffer('image/png')); +res.write(buffer); res.end(); ``` diff --git a/contents/zh/how-to/cross-platform/server.md b/contents/zh/how-to/cross-platform/server.md index 19ef0a0..9299f4e 100644 --- a/contents/zh/how-to/cross-platform/server.md +++ b/contents/zh/how-to/cross-platform/server.md @@ -38,6 +38,10 @@ chart.setOption({ // 输出字符串 const svgStr = chart.renderToSVGString(); + +// 如果不再需要图表,调用 dispose 以释放内存 +chart.dispose(); +chart = null; ``` 整体使用的代码结构跟在浏览器中使用一样,首先是`init`初始化一个图表实例,然后通过`setOption`设置图表的配置项。但是`init`传入的参数会跟在跟浏览器中使用有所不同: @@ -112,11 +116,17 @@ chart.setOption({ //... }); +const buffer = renderChart().toBuffer('image/png'); + +// 如果不再需要图表,调用 dispose 以释放内存 +chart.dispose(); +chart = null; + // 通过 Response 输出 PNG 图片 res.writeHead(200, { 'Content-Type': 'image/png' }); -res.write(renderChart().toBuffer('image/png')); +res.write(buffer); res.end(); ``` --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@echarts.apache.org For additional commands, e-mail: commits-h...@echarts.apache.org