Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-26682] Android: ES6 template strings causing memory leak + crash

GitHub Issuen/a
TypeBug
PriorityCritical
StatusClosed
ResolutionDuplicate
Resolution Date2020-12-04T20:31:20.000+0000
Affected Version/sRelease 7.5.0
Fix Version/sn/a
ComponentsAndroid
Labelsn/a
ReporterHans Knöchel
AssigneeAbir Mukherjee
Created2018-12-30T15:05:53.000+0000
Updated2020-12-04T20:31:20.000+0000

Description

When using the following example on Android (with ES6+ enabled), the app crashes:
const stringVar = 'myString';
const numberVar = 1.337;
const myValue = ${stringVar}${numberVar.toFixed(2).toLocaleString()} €;
Error:
[ERROR] TiExceptionHandler: (main) [428,32694] ti:/titanium.js:146
[ERROR] TiExceptionHandler: 	value: function(property, value) {
[ERROR] TiExceptionHandler:                 ^
[ERROR] TiExceptionHandler: RangeError: Maximum call stack size exceeded
[ERROR] TiExceptionHandler:     at Label.value (ti:/titanium.js:146:17)
[ERROR] TiExceptionHandler:     at onSummaryChanged (/alloy/controllers/trip/detail/expenses/index.js:113:34)
The whole thing works fine on iOS. Please provide a workaround, thx!

Comments

  1. Ewan Harris 2019-01-01

    [~hknoechel], does this definitely not happen when not using transpilation? There's nothing there that will be transpiled against that V8 version as far as I can see, I built an app with that code and am not seeing any signs. I also left an app running for 5 minutes and it didn't seem to crash for me. Is it an instant thing or a slow thing for you? If you're sure the issue is down to template literals you could try using string concatenation const myValue = stringVar + numberVar.toFixed(2).toLocaleString() + ' €';
  2. Rene Pot 2019-10-29

    I took another look at this ticket. It doesn't seem to cause any issues on my side (using SDK 8.2.1 & CLI 7.1.1). [~hknoechel] can you confirm for me your status on this ticket? Do you still have the problem or did it go away for you?
  3. Hans Knöchel 2019-11-04

    We workarounded by writing an own native module for date formatting and haven't looked into it again. So no prio for us anymore.
  4. Joshua Quick 2020-12-04

    I tested this with the newest Titanium and it doesn't crash on Android. As of Titanium 9.1.0, we added toLocaleString() support on Android as well as other Intl related APIs. So, I think we can close this. *Side Note:* Doing a myNumber.toFixed(2).toLocaleString() won't "localize" the number to a string since toFixed() returns a string. You can do the following instead.
       const stringVar = 'myString';
       const numberVar = 1.337;
       //const myValue = ${stringVar}${numberVar.toFixed(2).toLocaleString('de-DE')} €;
       const myValue = ${stringVar}${numberVar.toLocaleString(Ti.Locale.currentLocale, { maximumFractionDigits: 2, minimumFractionDigits: 2 })} €;
       

JSON Source