Out Of Memory in Codename One

2019-08-06 04:58发布

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条回答
啃猪蹄的小仙女
2楼-- · 2019-08-06 05:12

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.

查看更多
登录 后发表回答