RTI is using RTI_INT32_MAX as the maximal size for string when support for unbounded string is enabled. As mentioned in answer from https://answers.ros.org/question/299297/maximum-limit-of-string-in-ros2/ the memory is allocated for 0 elements by default and then reallocated as messages come in. So if you look at your memory usage it should not allocate 2GB of RAM to store the string. Similarly, if you look at the packets sent on wireshark or similar tool you will see that only the characters present in the string will be serialized and sent.
The max sample size is provided by the <TYPE>_Plugin_get_serialized_sample_max_size_ex Connext generated function. In this case it always returns: RTI_CDR_MAX_SERIALIZED_SIZE.
You can find the connext generated code in your build folder under <PACKAGE_NAME>/rosidl_typesupport_connext_cpp
For the std_msgs/String message it will be the files: rosidl_typesupport_connext_cpp/std_msgs/msg/dds_connext/String_Plugin.cxx rosidl_typesupport_connext_cpp/std_msgs/msg/dds_connext/String_.cxx