Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-23715] Android: Memory leak when window has listView inside

GitHub Issuen/a
TypeBug
PriorityHigh
StatusClosed
ResolutionFixed
Resolution Date2016-12-07T08:58:15.000+0000
Affected Version/sn/a
Fix Version/sRelease 6.1.0
ComponentsAndroid
Labelsandroid, leak, listview, memory
ReporterMateus Kamoei
AssigneeGary Mathews
Created2016-07-28T19:09:46.000+0000
Updated2017-01-23T16:37:39.000+0000

Description

Problem: After closing a window with a listView inside its activity never gets finished causing a memory leak. This occurs even if the listView has no elements or listeners in its template. Eventually all this leaked memory causes the application to crash. Steps to reproduce: 1. Start the application (attached listViewMemoryLeak.js script) 2. Create a heap dump in DDMS 3. Tap the 'ListView' or 'ListView empty' buttons 4. Tap the back button 5. Cause GC 6. Create a second heap dump in DDMS 7. Do a comparison of the two heap dumps with Eclipse Memory Analyzer. The second heap dump has multiple new and living objects compared to the first heap dump. If you tap the 'View' or 'ScrollView' buttons instead and repeat the same process you'll notice that this does not occur.

Attachments

FileDateSize
app.js2016-08-01T12:15:26.000+00002714
listViewMemoryLeak.js2016-07-28T18:46:07.000+00002418
memory_leak.pdf2016-08-01T12:15:28.000+0000337537

Comments

  1. Ricardo Ramirez 2016-07-28

    Hello ! I took a look at the code and this is not problem from our sdk, this is happening because you are not closing the windows, each time you open a window, it creates a new instance and if you open the window again it is creating a new one. To avid this you can close all windows before open a new one, to close a window, you only need to do it the same way you open it, just add in the code
    yourwindowvar.close();
    so you can close all the windows before open new ones in your events.
  2. Mateus Kamoei 2016-07-29

    Hi Ricardo, Thanks for the quick reply! So what you are suggesting is to add an androidback event for every window opened that calls window.close()? Also I still don't understand why there is a difference in the number of activities seen on the heap dump. In the following heap dump screen shot, in the attached test app I just tapped the "View" button and then tapped the back button. You can see there is only *1 TiActivity object*. [http://imgur.com/jJKxq3J] In this next heap dump screen shot, in the attached test app I tapped the "ListView" button and then tapped the back button. The result is there are *2 TiActivity objects* remaining. [http://imgur.com/3oZOV8v] I closed the app before both tests executions.
  3. Mateus Kamoei 2016-08-01

    Attached two new files: - memory_leak.pdf: steps to reproduce the issue; - app.js: new sample code.
  4. Ricardo Ramirez 2016-08-02

    Hello ! The ticket is moved, do not remember that the main issue is that exists a memory leak after close a window with a listview inside.
  5. Farzad Merzadyan 2016-09-27

    Using the monitor in IntelliJ, it states that clicking any of the buttons will cause leaked activities. The leak isn't attributed to only those activities containing the listview. For some reason, the activities aren't being destroyed.
  6. Gary Mathews 2016-11-17

    master: https://github.com/appcelerator/titanium_mobile/pull/8616
  7. Samir Mohammed 2017-01-13

    Verified fixed using the test code provided by [~gmathews] in https://github.com/appcelerator/titanium_mobile/pull/8616 was able to see number of objects and heap size decrease. To test Garys test case I took the following steps: 1. Start the application 2. Create a heap dump in DDMS 3. Tap the TI.UI.ListView or TI.UI.View empty buttons 4. Tap the back button 5. Cause GC 6. Create a second heap dump in DDMS 7. Repeat process on the latest SDK build and see if Ti.UI.ListView stops leaking memory *Environment*
       Appcelerator Command-Line Interface, version 6.1.0
       Nexus 6p (Android 7.1)
       Operating System Name: Mac OS X El Capitan
       Operating System Version: 10.11.6
       Node.js Version: 4.6.0
       npm: 4.2.8
       Titanium SDK Version: 6.1.0.v20170112013001
       Xcode: 8.2
       Appcelerator Studio: 4.8.1.201612050850
       

JSON Source