Skip to content

Memory leaks with CSS animation  #5731

Closed

Description

@NickIliev

From @RoyiNamir on April 20, 2018 6:33

I've created a simple new project via tns create bbb --ng

image

Added a CSS animation class via animate.css library :

app.css

@import '~nativescript-theme-core/css/core.light.css';
@import "~animate.css/animate.min.css";

.breath {
    animation-name: pulse;
    animation-duration: 2s;
    animation-iteration-count: infinite;
    animation-fill-mode: forwards;
}

And now I've created 7 images with that class. Some with manual images and some are via *ngFor :

image

This is the code for items.component.html

<ActionBar title="My App" class="action-bar"></ActionBar>
<GridLayout columns="*,*,*,*,*,*,*" rows="*">

    <StackLayout row="0" col="1"  >
        <Image class="breath " [src]="'~/images/hat00001.png'" stretch="aspectFit"></Image>
    </StackLayout>

    <StackLayout row="0" col="2"  >
        <Image class="breath " [src]="'~/images/hat00001.png'" stretch="aspectFit"></Image>
    </StackLayout>

    <Image *ngFor="let o of [1,2,3,4,5];let i = index;"
           [col]="i+3"
           [class]="'breath'"
          verticalAlignment="top"
           [src]="'~/images/hat0000'+(i+2)+'.png'"
           stretch="aspectFit"></Image>
</GridLayout>

There's nothing else. No TS code , no nothing. Just this html and css.

However , while writing down this issue ^ , look at the memory consumption :

image

Started at :

image

And now it's (keeps growing) :

image

Attached project : https://ufile.io/spicc

Video showing the ease growing leak :

video_2018-04-20_093614

Worth to mention: I'm not talking about the jumps. I'm talking about the easy growing memory consumption

Eventually the app is shutdown due to out of memory

Additional info :

image

Update: after 51 min - it's 0.2 GB :

image

This bug hurts the ability to use NS with games/continuous animations (said to be supported with css animations). :-(
Any workaround ?
BTW it also happens with Angular animations. ( i've created a test and still there's also a leak with Angular animations).

Copied from original issue: NativeScript/nativescript-angular#1291

Activity

  1. changed the title [-]Serious memory leaks with CSS animations[/-] [+]Memory leaks with CSS animation [/+] on Apr 24, 2018
  2. NickIliev commented on Apr 24, 2018

    @NickIliev
    ContributorAuthor

    @RoyiNamir thank you for reporting this issue and providing the detailed description and information.
    I can confirm that indeed the issue is reproducible and the memory leak is also observed in NativeScript Core application (--tsc).

    Steps to reproduce:

  3. NickIliev commented on Apr 24, 2018

    @NickIliev
    ContributorAuthor

    Update: it seems that changing the animation count from infinity to some large number is causing larger memory leak

    .breath {
        animation-name: pulse;
        animation-duration: 2s;
        animation-iteration-count: 100000;
        animation-fill-mode: forwards;
    }
    
  4. mid787 commented on Apr 24, 2018

    @mid787

    @NickIliev Hi. Thanks for update. To my understanding , the problem is that the animation code is not reset ( after each iteration) , or not GC'ed. it happened to me also with large number of animation count instead of infinite. ( however , I didn't compare between the growth of large num VS infinite).

  5. mid787 commented on May 11, 2018

    @mid787

    Any progress on this one ? it really puts NS out of game/simple-animations world ... Having said that it supports CSS3 animations

    Or is there anything we could do meanwhile instead?

  6. added this to the milestone on May 15, 2018
  7. NickIliev commented on Jul 4, 2018

    @NickIliev
    ContributorAuthor

    Tested on my side via this application and Android profiler and the memory leak is now fixed.

    @RoyiNamir @jogboms can you guys test with your own applications and verify that the fix is resolving the issue for your scenarios as well. (at this very moment the fix is in the master branch meaning you will need npm i tns-core-modules@next for testing)

  8. added
    ready for test
    and removed on Jul 4, 2018
  9. 11 remaining items

  10. weijyewang commented on Oct 24, 2018

    @weijyewang

    @tsonevn I did not do any profiling, just tested on Samsung Galaxy S7. I can feel some improvement, but after iterating indefinitely for changing the background color from red to transparent for over 10 minutes, the entire app experience some serious lag. Restarting the app will makes things smooth again, so I guess the memory problem still persist.

  11. mid787 commented on Oct 27, 2018

    @mid787

    The memory probl3m still remains. @nickillliev already knows about it

  12. modified the milestones: 5.0, 5.1 (TBD) on Nov 14, 2018
  13. david-alexandre-lopes commented on Nov 21, 2018

    @david-alexandre-lopes

    To me it gets even worst if you place the animated element behind a
    *ngif="something"
    or
    <ng-template></ng-template>

    If I hide it at run time, the CPU continues to work as if the animated element was there, and RAM starts increasing fast (not crazy fast, but fast).

  14. gogoout commented on Nov 22, 2018

    @gogoout

    The current workaround is having a animation-iteration-count: 10; instead of Infinity

  15. modified the milestones: 5.1, 5.2 (TBD) on Dec 5, 2018
  16. self-assigned this
    on Feb 19, 2019
  17. mid787 commented on Feb 25, 2019

    @mid787

    @ADjenkov , i dont understand. Was this fixed ? If yes , in what version?

  18. ADjenkov commented on Feb 25, 2019

    @ADjenkov
    Contributor

    @RoyiNamir this will be released officially as a patch version. It is also available in tns-core-modules@rc and tns-core-modules@next. You can take a look at the fix for more specific info related to the issue.

  19. mmeven commented on Jan 29, 2020

    @mmeven

    Hello,
    I've observed this memory leak again. Using the same kind of app as the one mentioned earlier, I've witnessed a 10mb memory usage increase over 5 minutes using the Android profiler. Could someone confirm I'm not mistaken ?

    I was using "tns-core-modules": "~6.3.0" and "nativescript-angular": "~8.20.3"

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