Ticket #1392 (closed defect: fixed)

Opened 10 months ago

Last modified 7 months ago

Review Window.open code, it may leak memory (how to release these resources?)

Reported by: Jani Laakso Owned by: Jani Laakso
Priority: undefined Milestone: User Interface Library 5.2.0 RC
Component: undefined Version:
Keywords: Cc:
Known Issue description:
Hours estimate: Deadline (dd.mm.yyyy):
Known Issue version (since): Known Issue title:
Hours done: Depends to:
Affects documentation: no
Known Issue workaround:
Affects release notes: yes Contract:

Description

Window class contains code that should be refactored.

If I call Window.open, it's resources cannot be released (unless releasing main window).

E.g. these reserve memory but there is no way to release these resources:

 main.addComponent(new Button(
                "Open a application-level window, with shared state",
                new Button.ClickListener() {
                    public void buttonClick(ClickEvent event) {
                        if (windowUrl == null) {
                            final Window w = new Window("Subwindow");
                            final Label l = new Label(txt);
                            l.setContentMode(Label.CONTENT_XHTML);
                            w.addComponent(l);
                            getApplication().addWindow(w);
                            windowUrl = w.getURL();
                        }
                        getApplication().getMainWindow().open(
                                new ExternalResource(windowUrl), "_new");
                    }
                }));
        main.addComponent(new Button(
                "Create a new application-level window, with it's own state",
                new Button.ClickListener() {
                    public void buttonClick(ClickEvent event) {
                        final Window w = new Window("Subwindow");
                        getApplication().addWindow(w);
                        final Label l = new Label(
                                "Each opened window has its own"
                                        + " name, and is accessed trough its own uri.");
                        l.setCaption("Window " + w.getName());
                        w.addComponent(l);
                        getApplication().getMainWindow().open(
                                new ExternalResource(w.getURL()), "_new");
                    }
                }));

Change History

Changed 10 months ago by Jani Laakso

Try with RobustnessSimple?, case #1392

Changed 9 months ago by Marc Englund

Subwindows can be released, the FeatureBrowser? code just does not (). "Native" windows are not so easy: we could send an XHR on page unload, but what if the user clicks 'back'? -> i.e native windows can not easily be released, because we don't know when to release.

NOTE Currenly the "x" on subwindows only hides the window, but does not remove from application; in effect it's very easy to forget to remove the window when it's closed. IMO the default behaviour should remove the window, but this might break old apps...

Example code to remove on close:

       window.addListener(new CloseListener() {
            public void windowClose(CloseEvent e) {
                if (getParent() != null) {
                      ((Window) getParent()).removeWindow(this);
                 }
            }
        });

A little unnecessarily complicated, huh?

Changed 9 months ago by Marc Englund

Apparently Window has been updated so that closed windows are removed by default (in [3704] )

Thus the only thing remaining is possibly removing closed native windows as well, but this is non-trivial, not reliable, and we're not even sure we want to do it (user browses in native window, comes back - what should happen?)

-> I'm closing this

Changed 9 months ago by Marc Englund

  • status changed from new to closed
  • resolution set to fixed

Changed 7 months ago by Joonas Lehtinen

  • milestone changed from User Interface Library 5.1.2 to User Interface Library 5.2.0

Milestone User Interface Library 5.1.2 deleted

Note: See TracTickets for help on using tickets.