Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

TArray not properly garbage collected?

I have the following code in my blueprint based on AActor.

 UHierarchicalInstancedStaticMeshComponent* MeshComponent;
 TArray<UHierarchicalInstancedStaticMeshComponent*> MeshComponents;

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.

Product Version: Not Selected
more ▼

asked Apr 06 '15 at 10:53 AM in C++ Programming

avatar image

1 1 2 4

avatar image switchblade_77 Aug 13 '16 at 03:09 AM

I hear GC is not yet supported for TArray

avatar image Roi Danton Feb 12 '17 at 10:00 PM

The documentation says, TArray is the only container that supports GC:

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().

avatar image Roi Danton Apr 08 '17 at 11:55 AM

The documentation seems to be a little bit outdated, since Steve said that TMap is supported by GC since UE4.9.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

To answer my own question.

The problem was that the array wasn't the only reference to the object once you spawn them since they are attached to the AActor.

I do this when I unload to remove the instances.

 TArray<UActorComponent*> components = GetComponentsByClass(UHierarchicalInstancedStaticMeshComponent::StaticClass());
 for (int32 i = 0; i < components.Num(); i++)

more ▼

answered Apr 08 '17 at 08:46 PM

avatar image

1 1 2 4

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question