Explictly destroy Allocations and Scripts

Bug: 28053584
Test: For the cherry-pick, built and ran the CTS tests.

Updated the auto generator to add calls to destroy() for Allocations
and Scripts in the generated CTS tests.

Change-Id: Ia999542bc18c7fa5bf86916b105f2ab587fbb616
(cherry picked from commit c970d5dcdd52ab592e1a03f32844892793f22ff9)
diff --git a/script_api/GenerateTestFiles.cpp b/script_api/GenerateTestFiles.cpp
index 3c28801..d907d37 100644
--- a/script_api/GenerateTestFiles.cpp
+++ b/script_api/GenerateTestFiles.cpp
@@ -303,6 +303,13 @@
     writeJavaCallToRs(false, generateCallToVerifier);
     writeJavaCallToRs(true, generateCallToVerifier);
 
+    // Generate code to destroy input Allocations.
+    for (auto p : mAllInputsAndOutputs) {
+        if (!p->isOutParameter) {
+            mJava->indent() << p->javaAllocName << ".destroy();\n";
+        }
+    }
+
     mJava->endBlock();
     *mJava << "\n";
 }
@@ -860,6 +867,14 @@
         }
         *mJava << ");\n";
     }
+
+    // Generate code to destroy output Allocations.
+    for (auto p : mAllInputsAndOutputs) {
+        if (p->isOutParameter) {
+            mJava->indent() << p->javaAllocName << ".destroy();\n";
+        }
+    }
+
     mJava->decreaseIndent();
     mJava->indent() << "} catch (Exception e) {\n";
     mJava->increaseIndent();
@@ -1028,6 +1043,18 @@
 
     file->endBlock();
     *file << "\n";
+
+    file->indent() << "@Override\n";
+    file->indent() << "protected void tearDown() throws Exception";
+    file->startBlock();
+
+    file->indent() << "script.destroy();\n";
+    file->indent() << "scriptRelaxed.destroy();\n";
+    file->indent() << "super.tearDown();\n";
+
+    file->endBlock();
+    *file << "\n";
+
     return true;
 }