StringRef can be sent in reply as a parameter, like below, but StringRef does not manage its memory directly, So where is it managed?(It will be helpful if you can tell me where the corresponding codes are)
Logically TLogPeekReply::arena owns the memory referenced by TLogPeekReply::messages, but there’s actually a bug (that apparently doesn’t manifest) here. arena needs to appear after messages in the call to serializer to ensure that arena really does own the memory. This requirement is described briefly here: foundationdb/flow at master · apple/foundationdb · GitHub.
That’s all mostly only relevant for using TLogPeekReply deserialized from a network message though. If you are constructing TLogPeekReply in order to send it it’s your responsibility to make sure that arena owns the underlying memory.
If the reply has a StringRef field and no Arena field, then the underlying memory for the StringRef doesn’t have an owner tied to the reply. Logically that’s a bug or at least highly unconventional. There are various unreliable ways that the memory might be kept alive long enough.
Usually for replies without Arenas we’d either have a Standalone<StringRef> or std::string instead.