Repository navigation
Conversation
tokenize() did not free the buffer from toNativeUtf8(), so each call leaked a copy of the input string. CFStringCreateWithCString copies the bytes, so free the buffer after the call.
Contributor
There was a problem hiding this comment.
🟢 Approval recommended
The buffer is freed with the matching allocator after its final use, with no blocking issues identified.
No open issues 🎉
What changed in this PR
Fixes a per-call native memory leak in string_tokenizer.tokenize() without changing its public API.
Changes:
- Retains the temporary UTF-8 pointer and frees it after Core Foundation copies its contents.
| File | Description |
|---|---|
packages/string_tokenizer/lib/string_tokenizer.dart |
Frees the temporary UTF-8 allocation after string creation. |
Review effort: Balanced
Contributor
Author
|
#548 replaced |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
tokenize()did not free the buffer fromtoNativeUtf8(), so each call leaked a copy of the input string.CFStringCreateWithCStringcopies the bytes, so the buffer is freed after the call.Evidence
Call
tokenize()200 times on a 1 MB string, then compare RSS (macOS):After: RSS -11 MB
tokenize('hello world 你好世界')returns[hello, world, 你, 好, 世界]before and after.Merge Danger
Door: two-way
Blast Radius: small
No API change.
CFStringCreateWithCStringdoes not keep the pointer.