Skip to content

Display warning about copy for lazy ByteString more prominent #98

@agrafix

Description

@agrafix

I had a huge memory-leak in my application because when reading the documentation for BSL.ByteString suggests that copy should allow the "parent" to be released for GC. I thought this was a bit suspicious, but went with it anyways and it turned out quite bad... So I checked the source:

-- | /O(n)/ Make a copy of the 'ByteString' with its own storage.
--   This is mainly useful to allow the rest of the data pointed
--   to by the 'ByteString' to be garbage collected, for example
--   if a large string has been read in, and only a small part of it
--   is needed in the rest of the program.
copy :: ByteString -> ByteString
copy cs = foldrChunks (Chunk . S.copy) Empty cs
--TODO, we could coalese small blocks here
--FIXME: probably not strict enough, if we're doing this to avoid retaining
-- the parent blocks then we'd better copy strictly.

Important part here is the FIXME which does not show up in the docs but is critical in my opinion. Can we move this there?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions