[VOL-4548] openonuAdapterGo - memory leak seen in long term tests

Change-Id: Ie3eb2048cebf8bf8b2f2a99ccd927d462000223a
diff --git a/internal/pkg/avcfg/omci_ani_config.go b/internal/pkg/avcfg/omci_ani_config.go
index 34ed185..cc023ba 100755
--- a/internal/pkg/avcfg/omci_ani_config.go
+++ b/internal/pkg/avcfg/omci_ani_config.go
@@ -1817,3 +1817,11 @@
 	oFsm.mutexChanSet.RUnlock()
 	return flagValue
 }
+
+// PrepareForGarbageCollection - remove references to prepare for garbage collection
+func (oFsm *UniPonAniConfigFsm) PrepareForGarbageCollection(ctx context.Context, aDeviceID string) {
+	logger.Debugw(ctx, "prepare for garbage collection", log.Fields{"device-id": oFsm.deviceID})
+	oFsm.pDeviceHandler = nil
+	oFsm.pOnuDeviceEntry = nil
+	oFsm.pOmciCC = nil
+}
diff --git a/internal/pkg/avcfg/omci_vlan_config.go b/internal/pkg/avcfg/omci_vlan_config.go
index 668d2c6..e97b0be 100755
--- a/internal/pkg/avcfg/omci_vlan_config.go
+++ b/internal/pkg/avcfg/omci_vlan_config.go
@@ -3229,3 +3229,11 @@
 		}
 	}
 }
+
+// PrepareForGarbageCollection - remove references to prepare for garbage collection
+func (oFsm *UniVlanConfigFsm) PrepareForGarbageCollection(ctx context.Context, aDeviceID string) {
+	logger.Debugw(ctx, "prepare for garbage collection", log.Fields{"device-id": aDeviceID})
+	oFsm.pDeviceHandler = nil
+	oFsm.pOnuDeviceEntry = nil
+	oFsm.pOmciCC = nil
+}
diff --git a/internal/pkg/avcfg/onu_uni_tp.go b/internal/pkg/avcfg/onu_uni_tp.go
index efb69be..c51c489 100755
--- a/internal/pkg/avcfg/onu_uni_tp.go
+++ b/internal/pkg/avcfg/onu_uni_tp.go
@@ -1009,3 +1009,14 @@
 	}
 	return false
 }
+
+// PrepareForGarbageCollection - remove references to prepare for garbage collection
+func (onuTP *OnuUniTechProf) PrepareForGarbageCollection(ctx context.Context, aDeviceID string) {
+	logger.Debugw(ctx, "prepare for garbage collection", log.Fields{"device-id": aDeviceID})
+	onuTP.baseDeviceHandler = nil
+	onuTP.onuDevice = nil
+	for k, v := range onuTP.PAniConfigFsm {
+		v.PrepareForGarbageCollection(ctx, aDeviceID)
+		delete(onuTP.PAniConfigFsm, k)
+	}
+}