解决电话界面内存泄露 1628/2 1628/head
authorluozheng <1732036298@qq.com>
Tue, 14 Jan 2025 10:11:18 +0000 (18:11 +0800)
committerluozheng <1732036298@qq.com>
Tue, 14 Jan 2025 10:11:18 +0000 (18:11 +0800)
code/sdk/application/wearable/fd230app/nativeui/makephone/src/CallingView.cpp
code/sdk/application/wearable/fd230app/nativeui/phone/include/PhoneCallView.h
code/sdk/application/wearable/fd230app/nativeui/phone/src/PhoneCallView.cpp

index 471bfc2..4355847 100644 (file)
@@ -83,6 +83,9 @@ CallingView::~CallingView()
     imagedial = nullptr;
 
     
+    delete imageheadset;
+    imageheadset = nullptr;
+
     delete imageperson;
     imageperson = nullptr;
     
index 59b8448..8878f6d 100644 (file)
@@ -45,7 +45,6 @@ namespace OHOS
     // 定义包含按钮初始化参数的结构体\r
     struct ButtonInitParams\r
     {\r
-        UIButton *button;\r
         const char *buttonNumber;\r
         int leftPos;\r
         int topPos;\r
@@ -74,7 +73,7 @@ namespace OHOS
         void Init();\r
         void DeInit();\r
         void container_child_init();\r
-        void initButton(const ButtonInitParams &params);\r
+        UIButton* initButton(const ButtonInitParams &params);\r
         void UpdateLabel(const std::string &text);\r
         void container_child_SetVisible(bool);\r
         void start_call_roll_timer();\r
@@ -92,21 +91,7 @@ namespace OHOS
         UILabel *label_ = nullptr;\r
         UILabel *label_4G = nullptr;\r
         UILabel *label_BT = nullptr;\r
-        UIButton *button1_ = nullptr;\r
-        UIButton *button2_ = nullptr;\r
-        UIButton *button3_ = nullptr;\r
-        UIButton *button4_ = nullptr;\r
-        UIButton *button5_ = nullptr;\r
-        UIButton *button6_ = nullptr;\r
-        UIButton *button7_ = nullptr;\r
-        UIButton *button8_ = nullptr;\r
-        UIButton *button9_ = nullptr;\r
-        UIButton *button0_ = nullptr;\r
-        UIButton *buttoncall_ = nullptr;\r
-        UIButton *buttondel_ = nullptr;\r
-        UIButton  *button_4G =NULL;\r
-        UIButton  *button_BT =NULL;\r
-        \r
+        UIButton *button_[12] = {nullptr};\r
     };\r
 } // namespace OHOS\r
 #endif\r
index d98534d..b6e1da1 100644 (file)
@@ -32,13 +32,9 @@ namespace OHOS
         return g_pPhoneCallView;\r
     }\r
 \r
-    void PhoneCallView ::initButton(const ButtonInitParams &params)\r
+    UIButton* PhoneCallView ::initButton(const ButtonInitParams &params)\r
     {\r
-        UIButton *button = params.button;\r
-        if (button == nullptr)\r
-        {\r
-            button = new UIButton();\r
-        }\r
+        UIButton *button = new UIButton();\r
 \r
         const char *buttonNumber = params.buttonNumber;\r
         int leftPos = params.leftPos;\r
@@ -69,6 +65,7 @@ namespace OHOS
         container_->Add(button);\r
         button->SetVisible(true);\r
 \r
+        return button;\r
         \r
     }\r
 \r
@@ -81,12 +78,6 @@ namespace OHOS
 \r
     void PhoneCallView::Init()\r
     {\r
-        if (container_ == nullptr)\r
-        {\r
-            container_ = new UIViewGroup();\r
-            container_->SetPosition(0, 0, 466, 466);\r
-            container_->SetStyle(STYLE_BACKGROUND_OPA, 0);\r
-        }\r
         // Add Label to App\r
         if (label_ == nullptr)\r
         {\r
@@ -110,23 +101,22 @@ namespace OHOS
         container_->Add(label_);\r
         label_->SetVisible(true);\r
         ButtonInitParams buttonParams[] = {\r
-            {button1_, BUTTON1, 68, 104, 104, 70, button1Path, button1Path},\r
-            {button2_, BUTTON2, 181, 104, 104, 70, button2Path, button2Path},\r
-            {button3_, BUTTON3, 293, 104, 104, 70, button3Path, button3Path},\r
-            {button4_, BUTTON4, 69, 182, 104, 70, button4Path, button4Path},\r
-            {button5_, BUTTON5, 182, 182, 104, 70, button5Path, button5Path},\r
-            {button6_, BUTTON6, 293, 182, 104, 70, button6Path, button6Path},\r
-            {button7_, BUTTON7, 69, 260, 104, 70, button7Path, button7Path},\r
-            {button8_, BUTTON8, 181, 260, 104, 70, button8Path, button8Path},\r
-            {button9_, BUTTON9, 293, 260, 104, 70, button9Path, button9Path},\r
-            {button0_, BUTTON0, 181, 338, 104, 70, button0Path, button0Path},\r
-            {buttoncall_, BUTTONCALL, 69, 338, 104, 70, buttonCallPath, buttonCallPath},\r
-            {buttondel_, BUTTONDEL, 293, 338, 104, 70, buttonDelPath, buttonDelPath},\r
+            { BUTTON1, 68, 104, 104, 70, button1Path, button1Path},\r
+            {BUTTON2, 181, 104, 104, 70, button2Path, button2Path},\r
+            { BUTTON3, 293, 104, 104, 70, button3Path, button3Path},\r
+            { BUTTON4, 69, 182, 104, 70, button4Path, button4Path},\r
+            { BUTTON5, 182, 182, 104, 70, button5Path, button5Path},\r
+            { BUTTON6, 293, 182, 104, 70, button6Path, button6Path},\r
+            { BUTTON7, 69, 260, 104, 70, button7Path, button7Path},\r
+            { BUTTON8, 181, 260, 104, 70, button8Path, button8Path},\r
+            { BUTTON9, 293, 260, 104, 70, button9Path, button9Path},\r
+            { BUTTON0, 181, 338, 104, 70, button0Path, button0Path},\r
+            { BUTTONCALL, 69, 338, 104, 70, buttonCallPath, buttonCallPath},\r
+            { BUTTONDEL, 293, 338, 104, 70, buttonDelPath, buttonDelPath},\r
         };\r
 \r
-        for (const auto &params : buttonParams)\r
-        {\r
-            initButton(params);\r
+        for(int i = 0;i<12;i++){\r
+            button_[i] = initButton(buttonParams[i]);\r
         }\r
     }\r
     static int8_t  roll_falg=0;//0.1s一次变换\r
@@ -213,89 +203,29 @@ namespace OHOS
         {\r
             container_->RemoveAll();\r
         }\r
-        if(container_child!=NULL)\r
+        if(container_child!=nullptr)\r
         {\r
             container_child->RemoveAll();\r
         }\r
-        if(button_4G!=NULL)\r
-        {\r
-            delete button_4G;\r
-            button_4G = nullptr;\r
-        }\r
-        if(button_BT!=NULL)\r
+        if(label_!=nullptr)\r
         {\r
-            delete button_BT;\r
-            button_BT = nullptr;\r
+            delete label_;\r
+            label_ = nullptr;\r
         }\r
-        if(label_4G!=NULL)\r
+        if(label_4G!=nullptr)\r
         {\r
             delete label_4G;\r
             label_4G = nullptr;\r
         }\r
-        if(label_BT!=NULL)\r
+        if(label_BT!=nullptr)\r
         {\r
             delete label_BT;\r
             label_BT = nullptr;\r
         }\r
-        if (button1_ != nullptr)\r
-        {\r
-            delete button1_;\r
-            button1_ = nullptr;\r
-        }\r
-        if (button2_ != nullptr)\r
-        {\r
-            delete button2_;\r
-            button2_ = nullptr;\r
-        }\r
-        if (button3_ != nullptr)\r
-        {\r
-            delete button3_;\r
-            button3_ = nullptr;\r
-        }\r
-        if (button4_ != nullptr)\r
-        {\r
-            delete button4_;\r
-            button4_ = nullptr;\r
-        }\r
-        if (button5_ != nullptr)\r
-        {\r
-            delete button5_;\r
-            button5_ = nullptr;\r
-        }\r
-        if (button6_ != nullptr)\r
-        {\r
-            delete button6_;\r
-            button6_ = nullptr;\r
-        }\r
-        if (button7_ != nullptr)\r
-        {\r
-            delete button7_;\r
-            button7_ = nullptr;\r
-        }\r
-        if (button8_ != nullptr)\r
-        {\r
-            delete button8_;\r
-            button8_ = nullptr;\r
-        }\r
-        if (button9_ != nullptr)\r
-        {\r
-            delete button9_;\r
-            button9_ = nullptr;\r
-        }\r
-        if (button0_ != nullptr)\r
-        {\r
-            delete button0_;\r
-            button0_ = nullptr;\r
-        }\r
-        if (buttoncall_ != nullptr)\r
-        {\r
-            delete buttoncall_;\r
-            buttoncall_ = nullptr;\r
-        }\r
-        if (buttondel_ != nullptr)\r
+        for(int i = 0;i<12;i++)\r
         {\r
-            delete buttondel_;\r
-            buttondel_ = nullptr;\r
+            delete button_[i];\r
+            button_[i] = nullptr;\r
         }\r
         if(call_roll_timer)\r
         {\r