Out Of Memory in Codename One

旧时模样 提交于 2019-12-13 18:17:04

问题


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.

How I can free this memory?

Code of changing forms:

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); - Static function for add SideBar menu to form.


回答1:


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.

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.



来源:https://stackoverflow.com/questions/29013092/out-of-memory-in-codename-one

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!