Comment

Comment by microtonal

No, that does not solve the problem. Consider this Java fragment:

   String someLargeString = ...;
   //...
   String interesting = someLargeString.substring(10, 20);
   someLargeString = null;
Now assume that someLargeString is garbage-collected after the last statement. Is the backing character array of interesting 10 chars long or the size of the backing array of someLargeString?

You don't know, unless you know what the implementation of String#substring does. Suppose that someLargeString's array was a couple of megabytes, you could be using 20 bytes of memory or megabytes for interesting.

(Note that in the case of Java they switched from a O(1) index-based slicing to O(n) copying some time ago.)

parent microtonal 10 years ago

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton