Does GC deal with TArray of float

Dear Community, I have two questions about containers of generic types (float, int, etc).

  1. If I use TArray::Remove* methods how Engine frees the memory? Does GC do it or container itself?
  2. Does it make sense to tag TArray of generic_data_type with UPROPERTY() in respect of GC operations?

No, TArray code is one reponcible for allocating memory for it’s contance and it’s just single sequence of bytes made of native array, it not really big memory management challenge as it is core of TArray function and requires only single pointer which is pernametly enclosed in TArray and it does never lose it… i mean without that pointer TArray can not function. This also means that TArray is safe to use else where without contact with GC, ofcorse this does not protect you from losing contact objects containing TArrays, the TArray code wont protect you from that. GC only deals with UObjects, which you may lose control of and forget by losing pointer causing potential memory leak.

There more impotent factors that array need to deal with, due to fact that resizing array requires memory reallocation (as new size may not fit in old location) and require copy of entire content to new location which effects performance, array keeps memory allocated bigger then the array size it self need and it is recommended to reserve memory to size of expected size of array to avoid those expensive reallocations. Thats why Remove wont deallocate memory in hope that removed space will be reused when you add new items, without need to reallocate.

TArray provides you function that controls this process, like reserve function allowing you to tell array to allocate memory for specific number of items:

And Shrink which deallocates all unused memory space, very useful if you know that size of array wont change anymore:

You can find many other array memory control functions allowing to optimize how it works:

UPROPERTY() is only needed when you have pointers of UObjects to keep track on them, remember that pointers are int like variables too
containing memory address

Thanks for answering. This gives me significant help in understanding the details of GC’s operation.