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"

Memory Leak With TArray of Struct

If i use this struct ( without USTRUCT() cause i don't need it to be in blueprint ) :

 struct FVisibleArea
     int32 VEmitType;
     TSet<int32> area;
     FVisibleArea(int32 NewVEmitType)
         VEmitType = NewVEmitType;

I Store them in This Array:

 TArray<FVisibleArea> VisibleAreas_T1;

Adding them by:


And when i want to remove area i just use This:


Will it cause Memory Leak? Cause I Don't destroy structure and TSet in it Manually.

Product Version: UE 4.11
more ▼

asked May 09 '16 at 07:31 PM in C++ Programming

avatar image

203 6 10 20

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

1 answer: sort voted first

This won't cause a memory leak, your structs and the TSet inside it will be automatically destroyed soon after VisibleAreas_T1 gets out of scope. You don't have to destroy them manually because you're not allocating memory manually (i.e. with the new operator).

The story would be different if there were pointers involved. In that case, if you have a pointer to a UObject you should store it in a variable marked UPROPERTY, and to support that, your class must be a UCLASS or USTRUCT. Not doing so would not give you a risk of memory leak, but rather that the object could be garbage collected too early by UE's built-in garbage collection which does reference counting via UPROPERTY marked variables.

If you create a non UObject pointer, its your own responsibility to delete it eventually.

more ▼

answered May 10 '16 at 11:56 AM

avatar image

Zhi Kang Shao
496 9 11 30

(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