In the first one I store all my instances and GC works fine.
If I divide my instances into separate components that I’ve added to MeshComponents it seems I get no GC, and every new run with “New editor window” causes more memory usage and less fps.
Works: MeshComponent with 100.000 instances
Doesn’t work: TArray of 100 MeshComponents with 1000 instances each.
TArrays have the added benefit of having their elements garbage collected. This assumes that the TArray is marked as a UPROPERTY, and that it stores UObject derived pointers.
Remember that currently, the only container class that can be marked as a UPROPERTY is TArray. This means other container classes cannot be replicated, saved, or have their elements garbage collected for you.
Furthermore, according to that quote and a corresponding code example (see link), UHierarchicalInstancedStaticMeshComponent does not need to be set with UPROPERTY().