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"

How to handle UObjects inside of a TMap

I have this going on inside one of my files:

 struct ItemInfo {
     int index;
     UGUIElement* guiElem; // This
 TMap<int, ItemInfo> map;

Whenever the player does something, a new element is added to this map with map.Add(x, { i, CreateWidget(world) }), eg. the map holds the actual data. This map gets cleared with a simple map.Empty() call at some point.

The problem is memory leaks. I know/think that TMap isn't going to be deallocating anything for me, so should I loop through it instead of just calling Empty()? I've thought about making guiElem a TUniquePtr instead of a raw pointer, but read that I shouldn't be using those smart pointers for UObjects. Since this isn't marked as a UPROPERTY() however, it's not going to be automatically garbage collected (I think). I also don't want to put that macro on it just for GC.

How should I properly deal with this situation?

Product Version: UE 4.13
more ▼

asked Oct 24 '16 at 02:28 AM in C++ Programming

avatar image

166 33 43 56

avatar image ZBender Oct 24 '16 at 07:50 PM

I might be completely of with my wild guess, but here is at least something to help you get further.

Based of this post about memory allocation and deallocation for structs: http://stackoverflow.com/questions/10252915/c-free-all-memory-used-by-struct

It is possible that you need to loop through each element of the map and delete guiElem before you call empty().

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

0 answers: sort voted first
Be the first one to answer this question
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