Issue 18227: Release objects related to linked items and loading bar
authorIván Perdomo <ivan.perdomo@openbravo.com>
Fri, 12 Aug 2011 18:51:54 +0200
changeset 13523 c094ddabc843
parent 13522 14a8a048eec9
child 13524 51b7b8c4cf6c
child 13526 fe669fa7121d
Issue 18227: Release objects related to linked items and loading bar
- The linked items field uses 2 datasources that needs to be released manually
- The loading bar when opening a new tab was not destroyed after showing a
window
- Cache the value of OB.MainView.TabSet in a local variable to avoid useless
property lookups
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/ob-view-form-linked-items.js
modules/org.openbravo.client.application/web/org.openbravo.client.application/js/utilities/ob-view-manager.js
--- a/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/ob-view-form-linked-items.js	Fri Aug 12 12:48:02 2011 +0200
+++ b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/form/ob-view-form-linked-items.js	Fri Aug 12 18:51:54 2011 +0200
@@ -370,6 +370,20 @@
       view.setAsActiveView();
     }
     return this.Super('focusChanged', arguments);
+  },
+
+  destroy: function () {
+    // Explicitly destroy the associated DataSource to prevent memory leaks
+    // http://forums.smartclient.com/showthread.php?p=70493
+    if(this.linkedItemDS) {
+      this.linkedItemDS.destroy();
+      this.likedItemDS = null;
+    }
+    if(this.linkedItemCategoryDS) {
+      this.linkedItemCategoryDS.destroy();
+      this.likedItemDS = null;
+    }
+    this.Super('destroy', arguments);
   }
 });
 
--- a/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/utilities/ob-view-manager.js	Fri Aug 12 12:48:02 2011 +0200
+++ b/modules/org.openbravo.client.application/web/org.openbravo.client.application/js/utilities/ob-view-manager.js	Fri Aug 12 18:51:54 2011 +0200
@@ -265,29 +265,30 @@
           // 1) view is not open and class not loaded (open view and show loading bar)
           // 2) view is not open but class was loaded (open view and show loading bar)
           // 3) view is open and class is loaded (show loading bar in open view)          
-          var viewTabId, tabTitle, loadingTab = vmgr.findLoadingTab(params);
-          
+          var viewTabId, tabTitle, loadingTab = vmgr.findLoadingTab(params), loadingPane,
+              tabSet = OB.MainView.TabSet;
+
           params = params || {};
-          
+
           if (loadingTab) {
             viewTabId = loadingTab.pane.viewTabId;
           } else if (!params.popup && viewName !== 'OBPopupClassicWindow' && !params.showsItself) {
             viewTabId = vmgr.views.getViewTabID(viewName, params);
             if (viewTabId) {
               // tab exists, replace its contents
-              var loadingPane = OB.Utilities.createLoadingLayout();
-              
+              loadingPane = OB.Utilities.createLoadingLayout();
+
               // make sure it gets found in the next round
               params.loadingTabId = viewTabId;
               loadingPane.viewTabId = viewTabId;
 
               // is used to prevent history updating
               loadingPane.isLoadingTab = true;
-              
+
               // refresh the existing tab
-              OB.MainView.TabSet.updateTab(viewTabId, loadingPane);
+              tabSet.updateTab(viewTabId, loadingPane);
               // and show it
-              OB.MainView.TabSet.selectTab(viewTabId);
+              tabSet.selectTab(viewTabId);
             } else {
               // create a completely new tab
               // first create a loading tab and then call again
@@ -320,7 +321,7 @@
           if (viewInstance && viewInstance.show && viewInstance.showsItself) {
             if (loadingTab) {
               delete params.loadingTabId;
-              OB.MainView.TabSet.removeTab(loadingTab.ID);
+              tabSet.removeTab(loadingTab.ID);
             }
             viewInstance.show();
             return;
@@ -329,10 +330,20 @@
           // eventhough there is already an open tab
           // still refresh it
           if (viewTabId !== null) {
+            loadingPane = tabSet.getTab(viewTabId) && tabSet.getTab(viewTabId).pane;
+
             // refresh the view
-            OB.MainView.TabSet.updateTab(viewTabId, viewInstance);
+            // Note: updateTab doesn't remove the previous loading tab
+            // http://www.smartclient.com/docs/8.1/a/b/c/go.html#method..TabSet.updateTab
+            tabSet.updateTab(viewTabId, viewInstance);
+
             // and show it
-            OB.MainView.TabSet.selectTab(viewTabId);
+            tabSet.selectTab(viewTabId);
+
+            // Destroying the loading tab
+            if(loadingPane && !viewInstance.myOB) {
+              loadingPane.destroy();
+            }
 
             // tell the viewinstance what tab it is on
             // note do not use tabId on the viewInstance
@@ -359,10 +370,10 @@
             // important part
             
             // the select tab event will update the history
-            if (OB.MainView.TabSet.getSelectedTab() && OB.MainView.TabSet.getSelectedTab().pane.viewTabId === viewTabId) {
+            if (tabSet.getSelectedTab() && tabSet.getSelectedTab().pane.viewTabId === viewTabId) {
               OB.Layout.HistoryManager.updateHistory();
             } else {              
-              OB.MainView.TabSet.selectTab(viewTabId);
+              tabSet.selectTab(viewTabId);
             }
 
             return;