修复训练设置Slice内存泄漏
authorCaisking <3449750381@qq.com>
Thu, 3 Oct 2024 12:38:18 +0000 (20:38 +0800)
committerCaisking <3449750381@qq.com>
Thu, 3 Oct 2024 12:38:18 +0000 (20:38 +0800)
code/sdk/application/wearable/fd230app/nativeui/traing/include/TraingNomalView.h
code/sdk/application/wearable/fd230app/nativeui/traing/src/TraingNomalView.cpp

index 3930b10..581ea61 100644 (file)
@@ -64,7 +64,6 @@ namespace OHOS
         TraingNomalView(TraingNomalView &&) = delete;
         TraingNomalView &operator=(TraingNomalView &&) = delete;
 
-        UIViewGroup *container_ = nullptr;
         UILabelExt *sporttitle_ = nullptr;
         UIButton *buttonGo_ = nullptr;
         UILabelButtonExt *buttonSet_ = nullptr;
index 47e881a..8f4bc3a 100644 (file)
@@ -72,7 +72,10 @@ namespace OHOS
     /* DeInit:删除组件*/
     void TraingNomalView::DeInit()
     {
-        container_->RemoveAll();
+        if(container_ != nullptr)
+        {
+            container_->RemoveAll();
+        }
         if (sporttitle_ != nullptr)
         {
             delete sporttitle_;
@@ -129,7 +132,7 @@ namespace OHOS
         container_->SetDraggable(true);
 
         PreLoad();
-        RootView::GetInstance()->Add(container_);
+        SetContainerView(container_);
         SetKeyActListener();
     }
 
@@ -156,10 +159,13 @@ namespace OHOS
     void TraingNomalView::OnStop()
     {
         View<TraingNomalPresenter>::OnStop();
+         if (container_ != nullptr)
+        {
+            container_->RemoveAll();
+            delete container_;
+            container_ = nullptr;
+        }
         RootView::GetInstance()->RemoveAll();
-
-        RootView::GetInstance()->ClearOnKeyActListener();
-        // FocusManager::GetInstance()->ClearFocus();
         return;
     }
 }