ngx-charts
ngx-charts copied to clipboard
Generating unique ids without memory leaks
The id() function now uses a Linear Congruential Generator with a 21-bit period so that it generates pseudo-random numbers without duplicates, without the need of a cache holding already used values.
Given the 4-digit mantissa of this method, after around 1.6 milion ids it will start to generate duplicates consistently, but it is still better than a stack-overflow as the old implementation (which, by the way came much before reaching the 1.6 milion limit).
What kind of change does this PR introduce? (check one with "x")
- [x] Bugfix
- [ ] Feature
- [ ] Code style update (formatting, local variables)
- [ ] Refactoring (no functional changes, no api changes)
- [ ] Build related changes
- [ ] CI related changes
- [ ] Other... Please describe:
What is the current behavior? (You can also link to an open issue here) #1310
What is the new behavior? No memory-leak, no stack overflow during usage, and it should be faster on average.
Does this PR introduce a breaking change? (check one with "x")
- [ ] Yes
- [x] No
If this PR contains a breaking change, please describe the impact and migration path for existing applications: ...
Other information:
@Hypercubed is there a reason why we're not using a library for this?