This code works if I pass a variable declared as const TArray<TSharedPtr<FJsonValue>> *OutArray as the second parameter, but leaves me wondering about 2 things:
Isn’t there a better way to use pointers in case of “OutArray” variable? Can I avoid using the native const “*” pointer here and use a smart pointer instead? Using TSharedPtr<TArray<TSharedPtr<FJsonValue>>> OutArray gives me compile time errors about assigning temporary object to a reference.
Why does trying to delete “OutArray” pointer later on gives me an exception at runtime? Does that mean UE4’s GC manages this pointer for me? How can I be aware if data reference by “*” pointer is managed by GC if it’s not an explicit “UPROPERTY()”?.
OutArray should just be a reference to a pointer that is pointing to a const TArray.
So if I pass in a const TArray<TSharedPtr<FJsonValue>> *myOutArray to FJsonObject::TryGetArrayField, when it returns myOutArray will be pointing to memory somewhere. Who’s managing that memory?
Maybe I just suck at C++ and I’m missing something?
A Shared Pointer owns the object it references, indefinitely preventing deletion of that object, and ultimately handling its deletion when no Shared Pointer or Shared Reference references it. A Shared Pointer can be empty, meaning it doesn’t reference any object. Any non-null Shared Pointer can produce a Shared Reference to the object it references.