MLCE-1245 Fixing runtime memory handling in delegate and ArmNN executor.

Neither the armnn_delegate nor the ArmNNExecutor unloaded their network
before being destructed. This was leaking significant memory.

Signed-off-by: Colm Donelan <colm.donelan@arm.com>
Change-Id: I61db2e6cbbff4ec4771e86ac71eab90c02389c9e
diff --git a/delegate/classic/src/armnn_delegate.cpp b/delegate/classic/src/armnn_delegate.cpp
index 52621ee..ed63215 100644
--- a/delegate/classic/src/armnn_delegate.cpp
+++ b/delegate/classic/src/armnn_delegate.cpp
@@ -95,12 +95,12 @@
                 tfLiteContext, parameters, static_cast<::armnnDelegate::Delegate*>(parameters->delegate->data_)));
         },
         // ArmnnSubgraph Free
-        .free = [](TfLiteContext* tfLiteContext, void* buffer) -> void {
-            armnn::IgnoreUnused(tfLiteContext);
+        .free = [](TfLiteContext*, void* buffer) -> void {
             if (buffer != nullptr)
             {
                 delete static_cast<ArmnnSubgraph*>(buffer);
             }
+
         },
         // ArmnnSubgraph Prepare
         .prepare = [](TfLiteContext* tfLiteContext, TfLiteNode* tfLiteNode) -> TfLiteStatus {
@@ -276,6 +276,8 @@
 
 ArmnnSubgraph::~ArmnnSubgraph()
 {
+    // We're finished with the network.
+    m_Runtime->UnloadNetwork(m_NetworkId);
     // The delegate holds its own Arm NN runtime so this is our last chance to print internal profiling data.
     std::shared_ptr<armnn::IProfiler> profiler = m_Runtime->GetProfiler(m_NetworkId);
     if (profiler && profiler->IsProfilingEnabled())
diff --git a/tests/ExecuteNetwork/ArmNNExecutor.cpp b/tests/ExecuteNetwork/ArmNNExecutor.cpp
index 58655c1..121d3fa 100644
--- a/tests/ExecuteNetwork/ArmNNExecutor.cpp
+++ b/tests/ExecuteNetwork/ArmNNExecutor.cpp
@@ -1,5 +1,5 @@
 //
-// Copyright © 2022-2023 Arm Ltd and Contributors. All rights reserved.
+// Copyright © 2022-2024 Arm Ltd and Contributors. All rights reserved.
 // SPDX-License-Identifier: MIT
 //
 
@@ -89,6 +89,11 @@
     }
 }
 
+ArmNNExecutor::~ArmNNExecutor()
+{
+    m_Runtime->UnloadNetwork(m_NetworkId);
+}
+
 void ArmNNExecutor::ExecuteAsync()
 {
 #if !defined(ARMNN_DISABLE_THREADS)
diff --git a/tests/ExecuteNetwork/ArmNNExecutor.hpp b/tests/ExecuteNetwork/ArmNNExecutor.hpp
index b0b29de..cbc8607 100644
--- a/tests/ExecuteNetwork/ArmNNExecutor.hpp
+++ b/tests/ExecuteNetwork/ArmNNExecutor.hpp
@@ -38,13 +38,18 @@
 {
 public:
     ArmNNExecutor(const ExecuteNetworkParams& params, armnn::IRuntime::CreationOptions runtimeOptions);
+    ~ArmNNExecutor();
+    ArmNNExecutor(const ArmNNExecutor&) = delete; // No copy constructor.
+    ArmNNExecutor & operator=(const ArmNNExecutor&) = delete; // No Copy operator.
 
     std::vector<const void* > Execute() override;
     void PrintNetworkInfo() override;
     void CompareAndPrintResult(std::vector<const void*> otherOutput) override;
 
 private:
-
+    ArmNNExecutor(ArmNNExecutor&&); // No move constructor.
+    ArmNNExecutor& operator=(ArmNNExecutor&&);  // No move operator.
+    
     /**
      * Returns a pointer to the armnn::IRuntime* this will be shared by all ArmNNExecutors.
      */