Clear as much of cc.Module as possible after GenerateBuildActions

Reduce peak memory usage by adding a CleanupAfterBuildActions method
that is called at the end GenerateBuidlActions, nad use it to clear as
much of cc.Module as possible.

This is a temporary measure, eventually the entire module should be
released by blueprint once all interactions are performed through
providers.

Test: all soong tests pass
Change-Id: Idc3390ae4506ff2eef3231691e1de7446067961a
diff --git a/cc/cc.go b/cc/cc.go
index 85d2ebf..c616165 100644
--- a/cc/cc.go
+++ b/cc/cc.go
@@ -2438,6 +2438,27 @@
 	}
 }
 
+func (c *Module) CleanupAfterBuildActions() {
+	// Clear as much of Module as possible to reduce memory usage.
+	c.generators = nil
+	c.compiler = nil
+	c.installer = nil
+	c.features = nil
+	c.coverage = nil
+	c.fuzzer = nil
+	c.sabi = nil
+	c.lto = nil
+	c.afdo = nil
+	c.orderfile = nil
+
+	// TODO: these can be cleared after nativeBinaryInfoProperties and nativeLibInfoProperties are switched to
+	//  using providers.
+	// c.linker = nil
+	// c.stl = nil
+	// c.sanitize = nil
+	// c.library = nil
+}
+
 func CreateCommonLinkableInfo(ctx android.ModuleContext, mod VersionedLinkableInterface) *LinkableInfo {
 	info := &LinkableInfo{
 		StaticExecutable:     mod.StaticExecutable(),