Quantcast
Channel: Active questions tagged react-native+typescript - Stack Overflow
Viewing all articles
Browse latest Browse all 6287

Locating memory leak React Native

$
0
0

I am currently trying to debug and find the culprit of a memory leak in my application (only on Android, works fine on iOS). See graph below for memory increasing. In the application I am running this function:

const prepareData = (   weather: Weather,   sources: ("source1" | "source2")[]) => {let unsortedHours: ComparisonWeather = { source1: [], source2: [] };let shortestAmountOfHours = 40;for (const source of sources) {  let hoursForGraph = weather[source].weather[0].hours    .concat(weather[source].weather[1].hours)    .slice()    .sort((a, b) => (new Date(a.time) > new Date(b.time) ? 1 : -1));  unsortedHours[source].push(    ...hoursForGraph      .slice()      .sort((a, b) => (new Date(a.time) > new Date(b.time) ? 1 : -1))  );  if (unsortedHours[source].length < shortestAmountOfHours) {    shortestAmountOfHours = unsortedHours[source].length;  }}console.log("After first loop");setGraphLength(shortestAmountOfHours);for (const source of sources) {  if (unsortedHours[source].length < shortestAmountOfHours) {    const diff = shortestAmountOfHours - unsortedHours[source].length;    shortestAmountOfHours = unsortedHours[source].length;    unsortedHours[source] = unsortedHours[source].splice(-diff);  }  console.log(`Length of source ${source}:`, unsortedHours[source].length);}return unsortedHours;};

The app dies a while after printing "After first loop" and no more things logged to the console. The memory usage can be seen in the image below. "After first loop" is printed around where the memory start increasing uncontrollably and Length of source ${source}: is never even printed even though like 20 seconds passes by.

Does anyone know the cuplrit of this memory leak? I really cant seem to pinpoint what is causing it!

Thanks!

enter image description here


Viewing all articles
Browse latest Browse all 6287

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>