2 ms·
Nope, that's one way to have a memory leak. But you can avoid the problem by using the new String(oldString) constructor - it copies only the part of the under
by brazzy 14y ago
Nope, that's one way to have a memory leak. But you can avoid the problem by using the new String(oldString) constructor - it copies only the part of the underlying char array that the String uses. You're absolutely right that it would be much better if all that were part of the API rather than an implementation detail.
The SO question and answers are confusing because they talk about two competely separate issues: the above and the interning mechanism.