4 ms·
Does this approach avoid the issue of substrings preventing the strings they refer to from being garbage collected (e.g. as in Java's substring() before JDK 7)?
by boygobbo 6y ago
Does this approach avoid the issue of substrings preventing the strings they refer to from being garbage collected (e.g. as in Java's substring() before JDK 7)?
- chriswarbo 6y agoAFAIK ByteString suffers this problem: substrings will prevent their whole array from being GCed. By default, data read from files, stdin, etc. is split into 64k chunks (e.g. see functions like 'hGetN' in http://hackage.haskell.org/package/bytestring-0.9.2.1/docs/src/Data-ByteString-Lazy.html http://hackage.haskell.org/package/bytestring-0.9.2.1/docs/s... ), so only the 64k chunks containing the parts we want will be kept. There is a function 'copy' which will explicitly return a copy of only the character range that's used, so the original can be GCed ( https://hackage.haskell.org/package/bytestring-0.10.10.0/docs/Data-ByteString.html#v:copy https://hackage.haskell.org/package/bytestring-0.10.10.0/doc... )
- boygobbo 6y agoThanks for the clarification. BTW I agree with tome - your comment above would make a great blog post.
- chriswarbo 6y agoIt's now at http://chriswarbo.net/blog/2020-06-08-haskell_strings.html http://chriswarbo.net/blog/2020-06-08-haskell_strings.html