Are standard c++ classes garbage collected?

Hey all, I’m currently chasing down an odd bug in a third party plugin that I wrote.

I have several data structs meant to transport information between my library dll and Unreal, exposed through DLLIMPORT/DLLEXPORT, with the intent of communicating between the two. Remarkably, structs instantiated in the library are fine, but structs (raw c++, not UStruct) that are instantiated in Unreal are causing a system access violation/corrupt memory exception when I pass them to the library. I have c++ lambdas (std::function) that I pass from Unreal and those callbacks work fine, but for whatever reason, all of my vanilla c++ structs are corrupt on arrival and throw exceptions.

Is Unreal garbage collecting my c++ structs? Or is it another issue?

To the best of my knowledge, only items created using Unreal Tags are managed by the engine GC system:
UClass
UFunction
UProperty
etc

I’m making this as a comment, not answer because I’d prefer someone with more expertise to confirm.

The structs that were causing problems contained std::string, which causes issues. Swapping over to const char * looks to have solved the problem, potentially. I’ll update tomorrow if I find out otherwise.

ya, for things like that, you’ll also want to use UE types:

FString
FVector
TChar
etc

C++ is still normal C++ so there is no magical gurbage collection made by UE4. UE4 has GC but it only deals with stuff that it manage and only UObjects classes are garbage collected by UE4, reflection system don’t support any other pointer types so they are not get destroyed automatically as engine don’t see there existence at all. Other non-pointer data are contained in class structure so it get wiped together with object.

I also think TSharedPtr TSharedRef also might get destroyed when all references are cleared, but i not sure about it, the main use of that pointers is to prevent invalid pointers so you should use them anyway if you deal with pointers other then UObject. But i’m also not sure how it works with standard C++ types.

best will be if you manually manage those pointers from library, as you would manually use them in other non-UE4 C++ project, tied them with UObject class life circle, of object initiation create/get pointers, destroy them on object destruction.

You should also imidietly as soon as you can, convert standard C++ types to UE4 types, as UE4 code don’t digest them at all. you saying you got issue with struct, if you use standard C++ don’t use USTRUCT() so UE4 won’t have any contact with it. But by doing that oyu wont be able to use this struct in bluerint, UFUNCTION and UPROPERTY (which is also optional). you should already convert to UE4 type when you put data in to struct that will be used in UE4 code.