Skip to content

Memory leak when using slide transition on Android (API Level 23) #2741

Closed

Description

@shripalsoni04

Did you verify this is a real problem by searching [Stack Overflow]

Yes

Tell us about the problem

In my sample application to show the memory leak issue, I have two pages. On first page there is only button and on tap on that button, we are navigated to page 2. On Page 2, I have a Label in StackLayout.

Now, when we set page transition to 'slide', it is causing a memory leak on Android API Level 23. Memory keep on increasing on transition till OOM. When I tested that on emulator with API Level 21 and 22, It is not causing any memory leak.

Please check the below heap dump taken on API 23 version showing ImageViews being generated on slide transition are remaining in memory.
memory-leak-heap-dump

Attaching the path2gc for this image, which may help you in finding the memory leak root.
path2gc

When I checked, what these images are, I found that it is creating screenshot of both the pages on navigation. Below are that Images, which are keep on adding in memory on transition.
image1

image2

Also, I found that, it is not releasing Label in Page 2 on transition. So Labels also keep on adding into memory.

Which platform(s) does your issue occur on?

Android

Please provide the following version numbers that your issue occurs with:

  • CLI: 2.3.0
  • Cross-platform modules: Tested on both 2.3.0 and 2.4.0-2016-09-16-4127
  • Runtime(s): tns-android: 2.3.0

Please tell us how to recreate the issue in as much detail as possible.

  1. Clone this sample app
  2. Run on Android API 23.
  3. Do transition between two pages for around 10 times.
  4. You can either log heapMemory on button click, or take heapDump from Android Monitor and analyse it in Android Studio or Eclipse MAT.

Is there code involved? If so, please share the minimal amount of code needed to recreate the problem.

Basic sample app to reproduce this issue: https://github.com/shripalsoni04/ns-transition-memory-leak

Activity

  1. colinskow commented on Sep 16, 2016

    @colinskow

    See the discussion at the bottom of #2571. I believe this is already fixed in master. Install tns-core-modules@next and test again.

  2. colinskow commented on Sep 16, 2016

    @colinskow

    Never mind, it looks like you are using the latest release already. I have additional tests for this issue at https://github.com/colinskow/tns-image-test

  3. shripalsoni04 commented on Sep 17, 2016

    @shripalsoni04
    ContributorAuthor

    @colinskow Thanks for sharing image tests.

    Actually in my case, the issue happens only when we use "Slide" transition for navigation on Android. It will work fine if you use "Fade" transition. In my sample app I don't have any image. The memory leak happens event when we have only Label in the page.

  4. tsonevn commented on Sep 17, 2016

    @tsonevn
    Contributor

    Hi @shripalsoni04,

    I tested the given scenario and I was able to reproduce this behavior with Slide transition while navigating and in non-NativeScript Angular2 project. I am attaching here also my sample project, where this problem has been reproduced.

    Regards,
    @tsonevn

  5. added this to the 2.4.0 milestone on Oct 10, 2016
  6. self-assigned this
    on Oct 10, 2016
  7. hshristov commented on Oct 10, 2016

    @hshristov
    Contributor

    Fixed with @next version of tns-core-modules and tns-core-modules-widgets. Could you please check with them if everything is ok?

  8. added
    ready for testTSC needs to test this and confirm against live production apps and automated test suites
    on Oct 10, 2016
  9. shripalsoni04 commented on Oct 15, 2016

    @shripalsoni04
    ContributorAuthor

    Hi @hshristov,

    I have tested the sample app with tns-core-modules and tns-core-modules-widgets 2.4.0-2016-10-14-4397 version. Below are the findings.

    When I tested this on genymotion emulator (heapSize: 96MB, API: 23), the transition images were not getting cleared till 14 transitions and after that the GC got called and it cleared some memory. After that I continued to do the transitions for around 16 more time, to check it GC is getting called or not..But it didn't call and it threw OOM and app crashed.

    When I tested this on device (heapSize: 256MB, API: 23), the transition images were kept on adding on memory till around 165 MB and then GC called and cleared some memory. I keep on doing transitions, and again around 165MB the GC called and cleared some memory. But it is not clearing all the memory. I analysed the heap dump and found that still some transition images are not getting removed from memory.

    So I think the issue is still there. Attaching the path2gc for one of the transition image, which may help you for further investigation.

    screen shot 2016-10-15 at 2 00 34 pm

    Edit: I also tried to explicitly call GC() on back navigation. But that also didn't help in avoiding memory leak.

    Let me know if you want any other information.

  10. hshristov commented on Oct 18, 2016

    @hshristov
    Contributor

    Hi @shripalsoni04,

    I assume you are using the attached sample in this issue, right?

  11. shripalsoni04 commented on Oct 18, 2016

    @shripalsoni04
    ContributorAuthor

    Yes. I am using the attached sample application with angular@2.1.0 and nativescript@2.4.0-2016-10-14-4397.

    I just pushed the updated package.json to the sample app.

  12. self-assigned this
    on Oct 21, 2016
  13. added and removed
    ready for testTSC needs to test this and confirm against live production apps and automated test suites
    on Oct 26, 2016
  14. removed their assignment
    on May 1, 2017
  15. lock commented on Aug 28, 2019

    @lock

    This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

  16. locked and limited conversation to collaborators on Aug 28, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions