Skip to content

Unsubscribe subscriptions on component unmount to prevent memory leaks#12618

Closed
Arooba-git wants to merge 1 commit into
primefaces:masterfrom
Arooba-git:master
Closed

Unsubscribe subscriptions on component unmount to prevent memory leaks#12618
Arooba-git wants to merge 1 commit into
primefaces:masterfrom
Arooba-git:master

Conversation

@Arooba-git
Copy link
Copy Markdown

Hello 👋
As part of our project, we are using Facebook's new Memlab tool to detect memory leaks in SPA applications and their libraries. While running the tool and analyzing the code of primeng, we saw that your project does a very good job of ensuring that all async operations are cancelled when components destroy. However, as per Memlab execution results, we found some unsubscribed subscriptions, causing the memory to leak (screenshots below).

[before]
prime-before Screen Shot 2023-02-12 at 7 26 01 PM

Hence we added the fix by unsubscribing the subscriptions on component unload, and you can see the count of leaks reducing noticeably:


prime-after-subscribe Screen Shot 2023-02-12 at 3 06 46 PM

Note. Host listener is used to ensure that ngOnDestroy is called not only when the class destroy, but also when the page refreshes, tab or browser closes or the user navigates away from the page [1]

We executed the unit test suite after the fixes and it passed TOTAL: 788 successfully (in and outside headless mode).

You can analyze this and other potential leak sources, if you like, by running Memlab with a scenario file covering maximum count of use cases.

Following is a sample of the scenario file we used (it needs to be a .js file but attaching here in .txt form):
primeeng-scenario-memlab.txt

Note that some other reported leaks (in Memlab) originated from Angular's internal objects, and hence were ignored.

References:
[1] https://wesleygrimes.com/angular/2019/03/29/making-upgrades-to-angular-ngondestroy.html

@vercel
Copy link
Copy Markdown

vercel Bot commented Feb 12, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Ignored Deployment
Name Status Preview Comments Updated
primeng ⬜️ Ignored (Inspect) Feb 12, 2023 at 0:08AM (UTC)

@Arooba-git
Copy link
Copy Markdown
Author

bump @cetincakiroglu

@github-actions
Copy link
Copy Markdown

This pull request has been automatically marked as stale. If this pull request is still relevant, please leave any comment, and we will keep it open. We are sorry that we have not been able to prioritize reviewing it yet. Your contribution is very much appreciated.

@github-actions github-actions Bot added the Resolution: Stale Issue or pull request is inactivity and unfortunately it will be *closed* if there is no response label Jun 17, 2023
@github-actions
Copy link
Copy Markdown

Closing this pull request after a prolonged period of inactivity. If this issue is still present in the latest release, please ask for this pull request to be reopened. Thank you for your understanding!

@github-actions github-actions Bot closed this Jun 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Resolution: Stale Issue or pull request is inactivity and unfortunately it will be *closed* if there is no response

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant