PlaceMe-SAS / single-spa-angular-cli

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

CLI apps leaking heap and node memory when unloaded

freon27 opened this issue · comments

Hi,

I'm experiencing memory leaks when loading and unloading a CLI application and I wanted to know if you've come across this issue? My test application is Angular 6 and as simple as possible (1 app component, no router).

As you can see in the picture, when I load and unload the application, manually triggering GC after each change, there seems to be leaks in node and heap memory. I'm not sure whether this is an Angular issue or an issue with the unmounting of the CLI applications.

image

I also saw memory issue, i don't know where it is, I unmount the angular app and the route, so I think it is not in my hand... thanks for this analyse. We have to work on it as soon as possible in my project, I will be back to you if I find something.
I have to test it with angular 6, maybe something has changed to unmount apps.

Oh did you not have the memory leak in previous Angular versions?

I was assuming it was maybe related to this which has been open over the last couple of releases of Angular:

angular/angular#13725

Please do let me know if there's anything I can do to help - I have time to invest if it gets us able to use Single-SPA :)

Ok thanks!
Do you want the permission to push on single spa angular cli to test something?

I guess for now I can just clone it and build locally right? Is there anything tricky about build process?

nope, only a npm link

I have to admit I'm a little lost for ideas right now. I've been poking around in the Angular source and it feels like you're doing all the right things. The only other thing I can think of is calling destroy on the platform itself which according to a comment in the source code should Destroy the Angular platform and all Angular applications on the page which sounds like it might be a possibility.

I'm not 100% sure how to do that within Single SPA lifecycle though and I guess it probably doesn't work for you (we currently have a limit to one active Angular app at a time because it seems to cause more trouble than it's worth to have them running in parallel).

Not sure if it's relevant, but came across the following code when researching another issue (note the comment - "Ensure Angular destroys itself on hot reloads.") :

platformBrowserDynamic().bootstrapModule(AppModule).then(ref => {
  // Ensure Angular destroys itself on hot reloads.
  if (window['ngRef']) {
    window['ngRef'].destroy();
  }
  window['ngRef'] = ref;

  // Otherwise, log the boot error
}).catch(err => console.error(err));

At this link: [(https://stackblitz.com/edit/angular-x32any?file=src%2Fmain.ts)]
Which was referenced here: [https://stackoverflow.com/questions/43991306/angular-4-5-6-global-variables/43991457#43991457]

Thanks for the tip.

Maybe @robinComa will have more luck with this but I've not been able to make it work (not seen any memory reduction).

Also, I suspect that for this module it won't be acceptable because that must destroy the whole of angular on the page, right? And people might be running multiple Angular apps simultaneously.

Thanks @pevans360 !
If you want, you can try to add it on single spa anuglar cli?
Could you try to do a PR?

Bye guys

@robinComa - Happened across this thread while researching a different angular memory issue. Haven't used this project (and just had to look up what a PR is). Was just trying to help out ... don't think this is the right spot for my 1st PR.

@pevans360 no problem, I understand
Thank you for your comment!

This project is deprecated (see #36). Use single-spa-angular@3, instead.

@freon27 any solution for this, I have the same problem, please could you tell me how you solved it

We didn't end up going with single SPA at the time due to this problem.

However my understanding is that Single SPA has changed a lot since then and I know other teams in our company have started using it, apparently without problems.