问题描述
我的应用程序使用SidePanel菜单作为导航,当我显示新表单或打开侧边栏面板时,该应用程序占用越来越多的内存.可能的是,这取决于在SideBar中使用某些Image处理(将图像蒙版到圆形)和大量使用URLImage类下载图像.但是最有可能是由于我没有释放以前表格的记忆.
My app used the SidePanel menu as navigation and when I show new form or open sidebar panel, the app takes more and more memory. Possible, it depended on using some Image processing (to mask image to circle) in SideBar and a lot of using URLImage class for downloading images. But most likely due to the fact that I did not free memory of the previous form.
如何释放此内存?
更改形式的代码:
public void showForm(FormBuilder form) {
if ( current == null ||
( ! form.getForm().getTitle().equals(current.getTitle()) )
) {
current = form.getForm();
if (!(form instanceof splash)) {
try {
sideMenu.addMenu(current);
} catch (IOException ex) {
}
}
current.show();
}
}
void sideMenu.addMenu(Form form); -用于将SideBar菜单添加到表单的静态函数.
void sideMenu.addMenu(Form form); - Static function for add SideBar menu to form.
推荐答案
以前的表格应"为GC.但是,如果您在以前的表单中引用了一个元素,则整个表单及其所有内容都将保留.这是因为每个组件直到其父窗体都一直引用其父窗体.
Previous forms "should" be GC'd. However, if you have a reference to one element in the previous form the whole form and all its content will be kept. This is because every component has a reference to its parent all the way up to the parent form.
您可以使用诸如NetBeans内存分析器之类的工具,也可以使用我们的性能分析器工具来跟踪内存使用情况.图像遮罩有点贵,但是如果使用URLImage
内置的遮罩,则所有内存开销都是GC的,因此这不成问题.
You can use tools like the NetBeans memory profiler and also our performance profiler tool in NetBeans to track down memory usage. Image masking is a bit expensive but if you used the one built into URLImage
all the memory overhead is GC'd so it shouldn't be a problem.
这篇关于代号一的内存不足的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!