# Swift is still sometimes so cumbersome

**URL:** <https://forums.swift.org/t/swift-is-still-sometimes-so-cumbersome/24772>\
**Category:** Using Swift\
**Created:** [May 22, 2019, 11:11pm UTC](https://forums.swift.org/t/swift-is-still-sometimes-so-cumbersome/24772 "2019-05-22T23:11:42Z")\
**Posts on this page:** 1\
**Showing post:** 4

<div class="post-metadata">

**Author:** ![ben-cohen](https://sea2.discourse-cdn.com/swift/user_avatar/forums.swift.org/ben-cohen/32/296_2.png) [@ben-cohen](https://forums.swift.org/u/ben-cohen)\
**Post date:** [May 22, 2019, 11:27pm UTC](https://forums.swift.org/t/swift-is-still-sometimes-so-cumbersome/24772/4 "2019-05-22T23:27:16Z")

</div>

> [@JetForMe](#):
>
> And I’m sure it’s been hashed to death, but why is a `Substring` not a `String` ? It sure seems to me to be one.

On this particular question: to avoid a memory leak you are possibly going to hit in this very use case. Imagine the string was 100mb, and you only want the first 100 characters stored in body. If body is a long-lived variable you are essentially leaking 100mb for the lifetime of `body`. There was recently a long thread investigating a major memory leak in a server-side NIO app that ended up being a variant of this problem (only with Data and ByteBuffer). This leak scenario was such a problem for Java that they changed string's substring op to make a copy (it used to share storage). But this messed other people up because that means substring ops go from being O(1) to being O(n).

---

_[View the full topic](https://forums.swift.org/t/swift-is-still-sometimes-so-cumbersome/24772)._
