using UnityEngine;
namespace Google.Maps.Examples.Shared {
///
/// This component is used to cleanup meshes (if any) when the associated
/// is destroyed.
///
///
/// This is done to prevent a memory leak that happens with decorations (such as parapets) as we
/// are dynamically loading/unloading map regions.
///
public class MeshCleaner : MonoBehaviour {
private void OnDestroy() {
// Does this GameObject have a mesh filter?
// We destroy the current mesh (by accessing sharedMesh)
MeshFilter mf = this.gameObject.GetComponent();
if (mf != null && mf.sharedMesh) {
Destroy(mf.sharedMesh);
}
}
}
}