Skip to content

@owned on core.os.d.ts's string functions: toFixed and Date strings stop leaking under rc - #107

Merged
ASDAlexander77 merged 1 commit into
mainfrom
rc-tofixed-leak
Nov 18, 2026
Merged

ASDAlexander77 merged 1 commit into
mainfrom
rc-tofixed-leak

Conversation

@ASDAlexander77

Copy link
Copy Markdown
Owner

Marks core/core.os.d.ts's six string functions @owned: convertNumber, convertInteger, timestamp_to_string, time_to_string, time_format, time_format_locale.

Each returns s, a view of a local char[]. Under rc the compiler copies a returned view at the return (#481), so the caller receives a string it owns. Left unmarked, they looked like C functions to lib.ts: the caller copied the result a second time and never released the function's own string. That leaked one string per toFixed, toExponential, toPrecision, Date.toString and toISOString call. #106 left them unmarked on the wrong assumption that they return a pointer into a buffer.

Measured (-mm=rc):

Probe Before After
1M (i + 0.5).toFixed(2) 34.4 MB 5.8 MB, flat
Date toString / toISOString / toExponential / toPrecision, 300K grew 5.9 MB, flat, same output as gc

Tests: tests.ps1 release (compile + JIT) passes in gc, rc, none and own. No compiler change is needed. The companion compiler PR (spread arguments passed to rest parameters, which fixes Array.join) was tested together with this branch.

🤖 Generated with Claude Code

… stop leaking under rc

convertNumber, convertInteger, timestamp_to_string, time_to_string, time_format and
time_format_locale each return `s`, a view of their local char[]. Under rc a view a function returns
is copied at the return (#481), so each hands its caller a string of its own at +1. Unmarked, they
were C functions to lib.ts: the caller copied the result again and never gave back the function's
own string - one leaked per `toFixed`, `toExponential`, `toPrecision`, `Date.toString`,
`toISOString` call. 1M `(i + 0.5).toFixed(2)`: 34.4 MB -> 5.8 MB, flat.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ASDAlexander77
ASDAlexander77 merged commit 1b265ba into main Nov 18, 2026
6 of 10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant