Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-25693] Android: Possible memory leak when setting ListSections on a ListView

GitHub Issuen/a
TypeBug
PriorityCritical
StatusClosed
ResolutionFixed
Resolution Date2018-02-26T22:16:40.000+0000
Affected Version/sn/a
Fix Version/sRelease 7.1.0
ComponentsAndroid
Labelslistitem, listview
ReporterRyan Aston
AssigneeYordan Banev
Created2018-01-22T21:30:29.000+0000
Updated2018-05-23T18:28:56.000+0000

Description

Looking at Android Device Monitor, memory usage appears to balloon on Android when using .setSections() on a ListView, particularly when the ListDataItem array for the ListSections is large and when sections are set multiple times. Memory doesn’t seem to clear even when the ListView is removed and its parent controller proxy is cleared and the controller is destroyed. The attached project demonstrates the issue. Clicking "Open List View" populates the ListView with 5 ListSections, each with 1,000 ListDataItems. Clicking "Repopulate List View" creates a new set of 5 sections and sets those sections on the existing list view. The memory footprint increases significantly with each repopulation and never seems to reset. Clicking "Close List View" destroys the controller holding the ListView, but the memory doesn’t appear to reset in that scenario either. Eventually the application runs out of memory and crashes. Additional notes: If I put a single ListSection in the XML for the ListView and use setItems on that single ListSection the memory does appear to reset, so it seems to be related to setSections, however in both scenarios if I close the view and destroy the controller the memory does not reset.

Attachments

FileDateSize
listviewleak.zip2018-01-22T21:30:26.000+000062610

Comments

  1. Yordan Banev 2018-01-31

    PR: https://github.com/appcelerator/titanium_mobile/pull/9784
  2. Lokesh Choudhary 2018-02-20

    [~ybanev], Can you please provide a backport.
  3. Yordan Banev 2018-02-20

    [~lchoudhary] I am still working on changes after the review feedback.
  4. Yordan Banev 2018-02-22

    7_1_X:https://github.com/appcelerator/titanium_mobile/pull/9868
  5. Lokesh Choudhary 2018-02-26

    FR Passed. PR's merged.
  6. Lokesh Choudhary 2018-03-06

    Verified the fix in SDK 7.2.0.v20180305152636 & 7.1.0.v20180306061214. Closing. Studio Ver: 5.0.0.201712081732 OS Ver: 10.13.2 Xcode Ver: Xcode 9.2 Appc NPM: 4.2.12 Appc CLI: 7.0.2 Daemon Ver: 1.0.1 Ti CLI Ver: 5.0.14 Alloy Ver: 1.11.0 Node Ver: 8.9.1 NPM Ver: 5.5.1 Java Ver: 1.8.0_101 Devices: ⇨ google Nexus 5 — Android 6.0.1 ⇨ google Nexus 6P — Android 8.0.0
  7. Mike Stancliffe 2018-05-22

    This issue seems to still be present in 7.1.1
  8. Ryan Aston 2018-05-23

    This issue is definitely not fixed in 7.1.1.GA or even in 7.2.0.v20180305152636 despite being marked as closed. Attempting to back port the original proposed fix into 7.1.0.GA introduced another issue. There are scenarios in our application where we may remove a ListSection or clear all of the ListSections from a ListView, however we want to maintain the ListSection(s) in memory so that they may be reinserted into the ListView. Doing so greatly increases performance in our application under certain scenarios. With the initial fix in place we noticed when setSections is called on the ListView with an empty array all of the ListSections are destroyed regardless of whether or not an accessible proxies are still present, thus causing the accessible proxies to now refer to null objects. A more accurate fix for this issue would only destroy a ListSection or ListSections upon removal from a ListView if there are no longer any accessible proxies associated with the ListSection(s) in question, allowing us to easily reuse ListSections. I have updated my original code sample to demonstrate this use case. I am unable to attach it to this JIRA, so I’ve put it on Google Drive: [https://drive.google.com/file/d/1wYTmjAbY3WHk-2gf1Fdz6rkk0E0SpHUo/view?usp=sharing](https://drive.google.com/file/d/1wYTmjAbY3WHk-2gf1Fdz6rkk0E0SpHUo/view?usp=sharing). Click OPEN LIST VIEW 2, Click REMOVE ALL LIST SECTIONS, then click REINSERT ALL LIST SECTIONS to demonstrate the behavior. Currently this works without issue, however the first proposed fix for this issue would destroy the ListSections when REMOVE ALL LIST SECTIONS (setSections([])) was clicked.

JSON Source