Wednesday, September 8, 2010

Re: Memory Leak IE7 & GWT 2.0.4

Hi,

You are clearing some panel by calling "clear()" method and adding in
it again. But clear method clear the panel only not instances. Browser
has a limitation of loading instances. If it exceeds, we get memory
leak issue. One way to solve is 'reloading the page'. Track the event
of page and reload the page from that point.


On Aug 26, 8:19 pm, chrisr <chris.robert.rowl...@gmail.com> wrote:
> I created a simple application in an attempt to reproduce a memory
> leak issue in our decently large GWT application.
>
> This test application basically contains a split panel with a button
> on the left, and a tab panel full of large blocks of text on the
> right.
> Clicking the reload button fires the reloadRight method, and does a
> panel.clear() to remove the old tab panel and a  panel.add() to add a
> new tab panel to the right panel.  Doing this repeatedly causes memory
> consumption to increase without bounds.
>
> For example, on the initial load IE7 uses around 35 MB.  125 clicks
> later its using nearly 1.5GB.
>
> Is this example doing something in a fundamentally incorrect way?
> How  can I keep memory usage from exploding like this?
>
> /* Example Below */
>
> package com.example.myproject.client;
>
> import com.google.gwt.core.client.EntryPoint;
> import com.google.gwt.event.dom.client.ClickEvent;
> import com.google.gwt.event.dom.client.ClickHandler;
> import com.google.gwt.user.client.ui.Button;
> import com.google.gwt.user.client.ui.DecoratedTabPanel;
> import com.google.gwt.user.client.ui.DecoratorPanel;
> import com.google.gwt.user.client.ui.HTML;
> import com.google.gwt.user.client.ui.HTMLPanel;
> import com.google.gwt.user.client.ui.HorizontalSplitPanel;
> import com.google.gwt.user.client.ui.RootPanel;
>
> /**
>  * Entry point classes define <code>onModuleLoad()</code>.
>  */
> public class TestApplication01 implements EntryPoint {
>
>        /**
>         * This is the entry point method.
>         */
>        public void onModuleLoad() {
>                RootPanel.get("container").add( new MainPanel() );
>        }
>
>        private class MainPanel extends DecoratorPanel{
>
>                private HorizontalSplitPanel hsp;
>                private HTMLPanel lPanel;
>                private HTMLPanel rPanel;
>                private DecoratedTabPanel tabPanel;
>                int rightPanelCount = 0;
>
>                public MainPanel(){
>                        hsp = new HorizontalSplitPanel();
>                        hsp.setSplitPosition("25%");
>                        hsp.setSize("800px", "400px");
>                        lPanel = new HTMLPanel("<div id=\"reloadButton
> \"/>");
>
>                        rPanel = new HTMLPanel("<div id=\"right-panel-
> contents\"/>");
>                        Button reloadButton = new ReloadButton(this);
>                        reloadButton.setVisible(true);
>                        lPanel.add( reloadButton, "reloadButton" );
>                        hsp.setLeftWidget(lPanel);
>                        hsp.setRightWidget(rPanel);
>                        this.add( hsp );
>                        reloadRight();
>                }
>
>                char[] chars = new char[] {' ',' ',' ', ' ', ' ',
> 'a','b','c','d','e','f','g','h','i','j','k','l','m',
>
> 'n','o','p','q','r','s','t','u','v','w','x','y','z' };
>
>                private String getSomeText(int length){
>                        StringBuffer sb = new StringBuffer(length);
>                        for ( int i=0; i<length; ++i ){
>
> sb.append( chars[ (int)Math.round(Math.random()*(chars.length-1)) ]);
>                                if ( i>0 && i % 60 == 0 )
>                                        sb.append("<br>");
>                        }
>                        return sb.toString();
>                }
>
>                protected void reloadRight(){
>                        ++rightPanelCount;
>                        rPanel.clear();
>
>                        tabPanel = new DecoratedTabPanel();
>                        tabPanel.setWidth("400px");
>                        tabPanel.setAnimationEnabled(true);
>
>                        String text = "Load count = "+rightPanelCount;
>
>                        tabPanel.add( new HTML(text
> +"<br>"+getSomeText((int)
> (Math.random()*500)+500000)), "Tab One");
>                        tabPanel.add( new HTML(text
> +"<br>"+getSomeText((int)
> (Math.random()*500)+500000)), "Tab Two");
>                        tabPanel.add( new HTML(text
> +"<br>"+getSomeText((int)
> (Math.random()*500)+500000)), "Tab Three");
>                        tabPanel.add( new HTML(text
> +"<br>"+getSomeText((int)
> (Math.random()*500)+500000)), "Tab Four");
>                        tabPanel.add( new HTML(text
> +"<br>"+getSomeText((int)
> (Math.random()*500)+500000)), "Tab Five");
>                        tabPanel.selectTab(0);
>
>                        rPanel.add( tabPanel, "right-panel-contents" );
>                }
>
>                private class ReloadButton extends Button{
>
>                        private MainPanel mainPanel;
>
>                        public ReloadButton(MainPanel p){
>                                super("Reload Right Panel");
>                                this.mainPanel = p;
>
> this.addClickHandler(getClickHandler());
>                        }
>
>                        private ClickHandler getClickHandler(){
>                                return new ClickHandler(){
>
>                                        @Override
>                                        public void onClick(ClickEvent
> event) {
>
> mainPanel.reloadRight();
>                                        }
>                                };
>                        }
>                }
>        }
>
>
>
> }

--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To post to this group, send email to google-web-toolkit@googlegroups.com.
To unsubscribe from this group, send email to google-web-toolkit+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.

No comments:

Post a Comment