stringStream implements ResourceObj and thus new() places it on the ResourceArea. The char* containing the printed content is allocated on the C heap.
It is not desireable to allocate the char* on the ResourceArea as if it is resized under a deeper ResourceMark than that of the stringStream, the char* will be invalidated when leaving that deeper ResourceMark's scope. This led to various errors before.
On the other side the fact that the destructor of stringStream must be called after allocating it with new() to free the char*, but delete() is not necessary/possible, is unexpected.
It is not desireable to allocate the char* on the ResourceArea as if it is resized under a deeper ResourceMark than that of the stringStream, the char* will be invalidated when leaving that deeper ResourceMark's scope. This led to various errors before.
On the other side the fact that the destructor of stringStream must be called after allocating it with new() to free the char*, but delete() is not necessary/possible, is unexpected.
- relates to
-
JDK-8224193 stringStream should not use Resource Area
- Resolved
-
JDK-8235998 [C2] Memory leaks during tracing after "8224193: stringStream should not use Resource Area".
- Resolved