On Mar 16, 2:19 pm, SmartKiller <[email protected]> wrote:
> It seems that GWT widgets are leaking memory. For testing i have
> created a sample application which create a series of panels
> containing Labels. If i allocate 1000 panels and clear() all of them
> there are still around 10000K memory remain to get free. Here is the
> code i have written"
>
> /**
>  * Entry point classes define <code>onModuleLoad()</code>.
>  */
> public class Test implements EntryPoint {
>         VerticalPanel tableRowContainer;
>         VerticalPanel mainVerticalPanel;
>         TextBox textbox;
>
>         /**
>          * This is the entry point method.
>          */
>         public void onModuleLoad() {
>                  Button addButton = new Button("Add");
>                  Button removeButton = new Button("Remove");
>                  Button clearButton = new Button("Clear");
>                  Button exitButton = new Button("Exit");
>                  tableRowContainer = new VerticalPanel();
>                  mainVerticalPanel = new VerticalPanel();
>                  textbox = new TextBox();
>
>                  addButton.addClickHandler(new ClickHandler(){
>                         �...@override
>                         public void onClick(ClickEvent event) {
>                          String tbText = textbox.getText();
>                          int num = Integer.parseInt(tbText);
>                          for (int i = 0; i< num ; i++) {
>                                  HorizontalPanel row = new HorizontalPanel();
>                                  Label l = new Label(" * First Label : " + i);
>                                  row.add(l);
>                                  l= null;
>                                  Label l1 = new Label(" ** Second Label : " + 
> i);
>                                  row.add(l1);
>                                  l1 = null;
>                                  Label l2 = new Label(" *** Third Label : " + 
> i);
>                                  row.add(l2);
>                                  l2 = null;
>                                  Label l3 = new Label (" **** Fourth Label :" 
> + i );
>                                  row.add(l3);
>                                  l3=null;
>                                  tableRowContainer.add(row);
>                                  row = null;
>                          }
>                         }
>                  });
>
>                  //This will explicitly remove each component added to panel
>                  removeButton.addClickHandler(new ClickHandler(){
>                         @Override
>                         public void onClick(ClickEvent event) {
>                          String tbText = textbox.getText();
>                          int num = Integer.parseInt(tbText);
>                          int i=0, j=0;
>                         // Window.alert("num " + num + "widgetcount " +
> rowPanel.getWidgetCount());
>                                  if (num <= 
> tableRowContainer.getWidgetCount()){
>                                          for (i = num - 1; i >= 0 ; i--) {
>                                                  HorizontalPanel h =
> (HorizontalPanel)tableRowContainer.getWidget(i);
>                                                  for (j=3; j>=0; j--){
>                                                          h.remove(j);
>                                                          
> //Window.alert("removing j = " + j + " : " + h.remove(j));
>                                                  }
>                                                  tableRowContainer.remove(i);
>                                                 // Window.alert("removing i " 
> + i + " : "+ rowPanel.remove(i));
>                                                 // h.removeFromParent();
>                                                  h = null;
>                                          }
>                                  }
>                         }
>                  });
>
>                  clearButton.addClickHandler(new ClickHandler(){
>                         @Override
>                         public void onClick(ClickEvent event) {
>
>                           tableRowContainer.clear();
>
>                         }
>                  });
>
>                  exitButton.addClickHandler(new ClickHandler(){
>                         @Override
>                         public void onClick(ClickEvent event) {
>                                 //clear everything; which is uncleared till 
> now.
>                                  tableRowContainer.clear();
>                                  mainVerticalPanel.clear();
>                                  tableRowContainer = null;
>
>                                  textbox = null;
>                                  mainVerticalPanel.removeFromParent();
>                                  RootPanel.get().remove(mainVerticalPanel); 
> //Only panel added is
> verticalPanel.
>                                  mainVerticalPanel = null;
>                         }
>                  });
>
>                  mainVerticalPanel.add(textbox);
>                  mainVerticalPanel.add(addButton);
>                  mainVerticalPanel.add(removeButton);
>                  mainVerticalPanel.add(clearButton);
>                  mainVerticalPanel.add(exitButton);
>                  mainVerticalPanel.add(tableRowContainer);
>
>                  RootPanel.get().add(mainVerticalPanel);
>
>                  addButton = null;
>                  removeButton= null;
>                  clearButton = null;
>                  exitButton = null;
>         }
>
> }
>
> I tried to free as much as possible. I dont know where the memory is
> leaking. The unfreed memory is reclaimed once i closed the tab or
> browser window itself. I have used Windows Task manager to check the
> memory consumption.
>
> Any help or pointer will be greately appreaciated.
>
> Thanks,
> Deepak

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

Reply via email to