Hi Torsten,

Memory for not anymore used ULC components is released when the garbage collector runs for the next time. ULC does not have any hard references to ULC components. Therefore it is not necessary to explicitly tell ULC to dispose ULC components.

Just make sure that you don't have any memory leaks, i.e. keep unwanted references to the ULC components from inside your ULC application. We recommend to use a standard Java profiler to check for unwanted references.

The snippet at the end of my mail shows that ULC really releases menu items that were removed from a menu bar.

Regards Dany


import com.ulcjava.base.application.AbstractAction;
import com.ulcjava.base.application.AbstractApplication;
import com.ulcjava.base.application.ULCBoxPane;
import com.ulcjava.base.application.ULCButton;
import com.ulcjava.base.application.ULCFrame;
import com.ulcjava.base.application.ULCMenu;
import com.ulcjava.base.application.ULCMenuBar;
import com.ulcjava.base.application.ULCMenuItem;
import com.ulcjava.base.application.event.ActionEvent;
import com.ulcjava.base.development.DevelopmentRunner;

public class MemoryUsageBehaviorSnippet extends AbstractApplication {
   public void start() {
       ULCBoxPane content = new ULCBoxPane(1, 0);
       content.add(new ULCButton(new ReplaceMenuBarContentAction()));
       content.add(new ULCButton(new RunGCAction()));
ULCMenuBar menuBar = new ULCMenuBar();
       MemoryUsageBehaviorSnippet.replaceMenuBarContent(menuBar);

       ULCFrame frame = new ULCFrame("Snippet");
       frame.setDefaultCloseOperation(ULCFrame.TERMINATE_ON_CLOSE);
       frame.setMenuBar(menuBar);
       frame.getContentPane().add(content);
       frame.setVisible(true);
   }

   public static void replaceMenuBarContent(ULCMenuBar menuBar) {
       ULCMenu menu = new ULCMenu("Menu");
       for (int i = 0; i < 5; i++) {
           menu.add(new ULCFinalizeMenuItem());
       }

       menuBar.removeAll();
       menuBar.add(menu);
   }

   public static class ULCFinalizeMenuItem extends ULCMenuItem {
       private static int sCounter = 0;

       public ULCFinalizeMenuItem() {
           super("MenuItem " + sCounter++);
       }

       protected void finalize() throws Throwable {
           System.out.println("finalize: " + getText());
       }
   }

   public static class ReplaceMenuBarContentAction extends AbstractAction {
       public ReplaceMenuBarContentAction() {
           putValue(NAME, "Replace Menu Bar Content");
       }

       public void actionPerformed(ActionEvent event) {
           ULCMenuBar menuBar = ULCFrame.getFrames()[0].getMenuBar();
           MemoryUsageBehaviorSnippet.replaceMenuBarContent(menuBar);
       }
   }

   public static class RunGCAction extends AbstractAction {
       public RunGCAction() {
           putValue(NAME, "Run GC");
       }

       public void actionPerformed(ActionEvent event) {
           Runtime.getRuntime().gc();
           Runtime.getRuntime().runFinalization();
       }
   }
public static void main(String[] args) { DevelopmentRunner.setApplicationClass(MemoryUsageBehaviorSnippet.class);
       DevelopmentRunner.main(args);
   }
}


Hofmann, Torsten wrote:
Hello

I have a question. When will the memory for not anymore used components be 
released. I have a strang behaviour, when i am creating dynamical views with 
ULCComponents (e.g. ULCMenuBar.removeAll()) the memory not decreases. When is 
the memory for example here the ULCMenuItems released?

How could i change this behaviour? Do i have to call the System.gc() und "null" 
all Objects?

Regards

Torsten Hofmann
Dipl. - Informatiker (FH)
IT Consultant Business Integration
Würth Phoenix GmbH
Drillberg 6
D-97980 Bad Mergentheim

Phone: +49 7931 91 6284
Fax: +49 7931 91 7284
E-Mail: [EMAIL PROTECTED]
Website: www.wuerth-phoenix.de

_______________________________________________
ULC-developer mailing list
[email protected]
http://lists.canoo.com/mailman/listinfo/ulc-developer


_______________________________________________
ULC-developer mailing list
[email protected]
http://lists.canoo.com/mailman/listinfo/ulc-developer

Reply via email to