Empty should be empty!

The shock and surprise when I saw the memory cost of a Stream created from an empty List in #Java was audible.
https://donraab.medium.com/empty-should-be-empty-c09e21edc205?source=friends_link&sk=c7809f108441527f48b2ef173bc7fbda

Empty Should be Empty

Why does empty cost so much in Java sometimes?

Medium
@TheDonRaab hi! You cannot return a singleton stream from an empty list, as any stream has a state. It tracks whether it's consumed, so you get IllegalStateException when trying to consume it twice. Also, you can register close handlers via onClose(). I believe, LazyIterable doesn't have such a (arguably not very useful but still) feature.
@TheDonRaab in fact, streams should be short-lived, unlike collections. If you have more than hundred of stream instances in your heap at any random point of time, likely you are doing something wrong. Streams are born to die quickly, they likely do not survive the first GC evacuation. Hence, it's usually not a problem if you allocate some more bytes.
@TheDonRaab This becomes mostly problematic with flatMap, when you create tons of small streams. E.g., adding .flatMap(Optional::stream) to flatten a stream of optionals may cause a performance issue. But now, you can replace this with .<T>mapMulti(Optional::ifPresent) to avoid intermediate streams.