Jgraphx内存不足-Java [英] Jgraphx out of memory - Java

查看:100
本文介绍了Jgraphx内存不足-Java的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从JAVA中创建的mxgraph创建一个mxgraph和一个图像.下面是从mxgraph创建图像的代码.

I am trying to create an mxgraph and a image from the created mxgraph in JAVA. Below is the code to create the image from mxgraph.

BufferedImage image = mxCellRenderer.createBufferedImage(graph,
               null, 1, Color.WHITE, graphComponent.isAntiAlias(), null,
               graphComponent.getCanvas());

// Creates the URL-encoded XML data
mxCodec codec = new mxCodec();
String xml = URLEncoder.encode(mxXmlUtils.getXml(codec.encode(graph.getModel())), "UTF-8");
mxPngEncodeParam param = mxPngEncodeParam.getDefaultEncodeParam(image);
param.setCompressedText(new String[] { "mxGraphModel", xml });

//Saves as a PNG file
outputStream = new FileOutputStream(new File("graph.jpg"));

ImageIO.write(image, "jpg", outputStream);
outputStream.close();
image = null;

我正在图形中使用分层布局.

I am using hierarchical layout in the graph.

但是在为更大的图形创建图像时,我遇到了内存不足的错误.

But I am getting the out of memory error on creating the image for larger graph.

我如何摆脱此内存问题(除了增加堆大小之外)? 除了增加堆大小之外,还有其他解决方法吗?

How can i get rid of this memory issue (apart from increasing the heap size)? Is there any other alternate way to solve this problem (apart from increasing the heap size)?

推荐答案

在此处查看此帖子:

http://forum.jgraph. com/questions/5408/save-as-png-detect-out-of-memory

尤其是底部. JGraphX中有一项检查,确定是否有足够的内存.那是错误的.可能没有足够的内存,因为GC尚未运行.如果GC运行,则将释放内存,并且createBufferedImage方法可能成功.因此,应该只在try {...} catch(Error err} {...}块中分配内存,而不是检查可用内存.

especially the bottom part. There's a check in JGraphX which determines if there's enough memory. That one is wrong. There may not be enough memory because the GC hasn't run yet. If the GC runs, then memory would be freed and the createBufferedImage method could be successful. So instead of checking for the free memory, the memory should have just been allocated in a try { ... } catch( Error err} { ... } block.

这篇关于Jgraphx内存不足-Java的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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