Memory usage: Optimize memory usage.
authorminkee.lee <minkee.lee@samsung.com>
Tue, 3 Jun 2014 08:34:45 +0000 (17:34 +0900)
committerminkee.lee <minkee.lee@samsung.com>
Fri, 13 Jun 2014 11:22:59 +0000 (20:22 +0900)
- Fix image resource release.
- Fix memory leak when launch emulator.

Change-Id: I24255fef15a25af0079aa4dffbebe95ccf46b8fc
Signed-off-by: minkee.lee <minkee.lee@samsung.com>
common-project/src/org/tizen/emulator/manager/ui/detail/DetailViewPage.java
common-project/src/org/tizen/emulator/manager/ui/detail/PEmptyViewPage.java
common-project/src/org/tizen/emulator/manager/ui/detail/PInfoViewPage.java
common-project/src/org/tizen/emulator/manager/ui/detail/PModifyViewPage.java
common-project/src/org/tizen/emulator/manager/ui/list/VMButtonFactory.java
common-project/src/org/tizen/emulator/manager/vms/EmulatorVMList.java
common-project/src/org/tizen/emulator/manager/vms/helper/MonitoringEmulator.java

index 5e682ef..4650c6b 100644 (file)
@@ -39,7 +39,6 @@ import org.eclipse.swt.layout.FormData;
 import org.eclipse.swt.layout.FormLayout;
 import org.eclipse.swt.widgets.Composite;
 import org.eclipse.swt.widgets.Label;
-
 import org.tizen.emulator.manager.resources.ColorResources;
 import org.tizen.emulator.manager.resources.FontResources;
 import org.tizen.emulator.manager.resources.ImageResources;
@@ -59,6 +58,7 @@ public abstract class DetailViewPage {
        protected Composite buttonComp  = null;
 
        protected int ITEM_COUNT = 11;
+       protected int itemListCount = 0;
 
        public int checkItemCountwithSize() {
                int h = parent.getSize().y - 30 - 36 - 60;
@@ -170,42 +170,77 @@ public abstract class DetailViewPage {
        }
 
        public void settingItemList() {
-               Image image  = PatchImageResources.getDetailListView(checkItemCountwithSize());
-               Image image2 = PatchImageResources.getDetailListView2(checkItemCountwithSize());
+               int beforeItemCount = ITEM_COUNT;
+               int currentItemCount = checkItemCountwithSize();
+               boolean needItemListCheck = false;
+               if (beforeItemCount != currentItemCount
+                               || itemListBack.getBackgroundImage() == null ) {
+                       needItemListCheck = true;
+                       Image image  = PatchImageResources.getDetailListView(currentItemCount);
+                       Image image2 = PatchImageResources.getDetailListView2(currentItemCount);
 
-               itemListBack.setBackgroundImage(image);
-               scrolledList.setBackgroundImage(image2);
+                       if (itemListBack.getBackgroundImage() != null) {
+                               itemListBack.getBackgroundImage().dispose();
+                       }
+                       if (scrolledList.getBackgroundImage() != null) {
+                               scrolledList.getBackgroundImage().dispose();
+                       }
 
-               FormData data = new FormData();
-               data.left       = new FormAttachment(0, 10);
-               data.top        = new FormAttachment(itemListTop, 0);
-               data.height = image.getImageData().height;
-               data.width      = image.getImageData().width;
-               itemListBack.setLayoutData(data);
-               itemListBack.setSize(data.width, data.height);
+                       itemListBack.setBackgroundImage(image);
+                       scrolledList.setBackgroundImage(image2);
 
-               data = new FormData();
-               data.left       = new FormAttachment(0, 0);
-               data.top        = new FormAttachment(0, 0);
-               int bottomGap = image.getImageData().height - image2.getImageData().height;
-               data.bottom = new FormAttachment(100, -bottomGap);
-               data.height = image2.getImageData().height;
-               data.width = image2.getImageData().width;
-               scrolledList.setSize(data.width, data.height);
-               scrolledList.setLayoutData(data);
-
-               int count = checkItemCount();
-               if (count != 0) {
-                       Image image3 = PatchImageResources.getDetailListView2(count);
-                       Point size = new Point(image3.getImageData().width,
-                                       image3.getImageData().height);
-                       if (stackLayout.topControl != null) {
+                       FormData data = new FormData();
+                       data.left       = new FormAttachment(0, 10);
+                       data.top        = new FormAttachment(itemListTop, 0);
+                       data.height = image.getImageData().height;
+                       data.width      = image.getImageData().width;
+                       itemListBack.setLayoutData(data);
+                       itemListBack.setSize(data.width, data.height);
+
+                       data = new FormData();
+                       data.left       = new FormAttachment(0, 0);
+                       data.top        = new FormAttachment(0, 0);
+                       int bottomGap = image.getImageData().height - image2.getImageData().height;
+                       data.bottom = new FormAttachment(100, -bottomGap);
+                       data.height = image2.getImageData().height;
+                       data.width = image2.getImageData().width;
+                       scrolledList.setSize(data.width, data.height);
+                       scrolledList.setLayoutData(data);
+               }
+
+               int beforeItemListCount = itemListCount;
+               int currentItemListCount = checkItemCount();
+               if (stackLayout.topControl == null) {
+                       if (beforeItemListCount != currentItemListCount) {
+                               Image image3 = PatchImageResources.getDetailListView2(currentItemListCount);
+                               Point size = new Point(image3.getImageData().width,image3.getImageData().height);
+                               image3.dispose();
+                               itemList.setSize(size);
+                               itemList.layout();
+                       }
+               } else {
+                       if (stackLayout.topControl.getBackgroundImage() == null) {
+                               Image image3 = PatchImageResources.getDetailListView2(currentItemListCount);
+                               Point size = new Point(image3.getImageData().width,image3.getImageData().height);
                                stackLayout.topControl.setBackgroundImage(image3);
                                stackLayout.topControl.setSize(size);
+                               itemList.setSize(size);
+                               itemList.layout();
+                       } else {
+                               Point size = new Point(stackLayout.topControl.getBackgroundImage().getImageData().width,
+                                               stackLayout.topControl.getBackgroundImage().getImageData().height);
+                               if (needItemListCheck || beforeItemListCount != currentItemListCount) {
+                                       stackLayout.topControl.getBackgroundImage().dispose();
+                                       Image image3 = PatchImageResources.getDetailListView2(currentItemListCount);
+                                       size = new Point(image3.getImageData().width,image3.getImageData().height);
+                                       stackLayout.topControl.setBackgroundImage(image3);
+                                       stackLayout.topControl.setSize(size);
+                               }
+                               itemList.setSize(size);
+                               itemList.layout();
                        }
-                       itemList.setSize(size);
-                       itemList.layout();
                }
+
                itemListBack.layout(true, false);
        }
 
index 4782f84..d696b55 100644 (file)
@@ -68,7 +68,8 @@ public class PEmptyViewPage extends DetailViewPage {
 
        @Override
        public int checkItemCount() {
-               return checkItemCountwithSize();
+               itemListCount = checkItemCountwithSize();
+               return itemListCount;
        }
 
        @Override
index 0658e67..0c86c1f 100644 (file)
@@ -268,7 +268,8 @@ public class PInfoViewPage extends DetailViewPage {
        @Override
        public int checkItemCount() {
                if (infoItemList == null || topViewList == null) {
-                       return checkItemCountwithSize();
+                       itemListCount = checkItemCountwithSize();
+                       return itemListCount;
                }
 
                int count = 0;
@@ -277,7 +278,8 @@ public class PInfoViewPage extends DetailViewPage {
                        count += i.getCount();
                }
 
-               return count;
+               itemListCount = count;
+               return itemListCount;
        }
 
        @Override
index 686df04..fcedaa7 100644 (file)
@@ -276,7 +276,8 @@ public class PModifyViewPage extends DetailViewPage
        @Override
        public int checkItemCount() {
                if (modifyItemList == null || topViewList == null) {
-                       return checkItemCountwithSize();
+                       itemListCount = checkItemCountwithSize();
+                       return itemListCount;
                }
 
                int count = 0;
@@ -285,7 +286,8 @@ public class PModifyViewPage extends DetailViewPage
                        count += i.getCount();
                }
 
-               return count;
+               itemListCount = count;
+               return itemListCount;
        }
 
        @Override
index 1e783a7..0736e4a 100644 (file)
@@ -30,7 +30,6 @@
 package org.tizen.emulator.manager.ui.list;
 
 import java.util.ArrayList;
-
 import org.eclipse.swt.SWT;
 import org.eclipse.swt.events.MouseEvent;
 import org.eclipse.swt.events.MouseListener;
index e87d3aa..c285b48 100644 (file)
@@ -54,10 +54,16 @@ import org.tizen.emulator.manager.vms.xml.ObjectFactory;
 
 public class EmulatorVMList {
        static EmulatorVMList instance = null;
+       static JAXBContext context = null;
 
        static {
                synchronized(EmulatorVMList.class) {
                        instance = new EmulatorVMList();
+                       try {
+                               context = JAXBContext.newInstance(EmulatorConfiguration.class);
+                       } catch (JAXBException e){
+                               EMLogger.getLogger().info(e.getMessage());
+                       }
                }
        }
 
@@ -173,12 +179,9 @@ public class EmulatorVMList {
        }
 
        public VMProperty parseXML(File configFile) {
-               JAXBContext context = null;
                JAXBElement<EmulatorConfiguration> element = null;
 
                try {
-                       context = JAXBContext.newInstance(EmulatorConfiguration.class);
-                       
                        Unmarshaller unmarshaller = context.createUnmarshaller();
                        element = unmarshaller.unmarshal(new StreamSource(configFile), EmulatorConfiguration.class);
                } catch (JAXBException e) {
@@ -210,10 +213,7 @@ public class EmulatorVMList {
        }
 
        public boolean storeXML(VMProperty property) {
-               JAXBContext context = null;
-
                try {
-                       context = JAXBContext.newInstance(EmulatorConfiguration.class);
                        Marshaller marshaller = context.createMarshaller();
                        marshaller.setProperty(Marshaller.JAXB_ENCODING, "UTF-8");
                        marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
index c66f64b..13aa1d5 100644 (file)
@@ -208,7 +208,16 @@ class StdOut implements Runnable {
                        try {
                                do {
                                        msg = reader.readLine();
-                                       list.add(msg);
+                                       if (msg != null) {
+                                               list.add(msg);
+                                       } else {
+                                               try {
+                                                       Thread.sleep(100);
+                                               } catch (InterruptedException e) {
+                                                       // TODO Auto-generated catch block
+                                                       e.printStackTrace();
+                                               }
+                                       }
                                } while (CheckingRunningEmulator.isContains(emName));
                        } catch (IOException e) {
                                EMLogger.getLogger().info(e.getMessage());