Skip to content

Conversation

@VladimirAmiorkov
Copy link
Contributor

PR Checklist

What is the current behavior?

When using the Angular createEmbeddeedView from the ViewContainerRef, after calling clear() the created NativeScript Views are left in the memory

What is the new behavior?

When using the Angular createEmbeddeedView from the ViewContainerRef, after calling clear() the created NativeScript Views are collected by the GC and a no longer in the memory

Fixes/Implements/Closes #[Issue Number].
ProgressNS/nativescript-ui-feedback#825

public onUnloaded(): void {
this.unsubscribeFromDynamicUpdates();
this.view = undefined;
this._matchInvalid = false;
Copy link
Contributor

@facetious facetious Oct 4, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This variable is poorly named. "Match invalid = false" implies that the match is valid, but you're about to set the match to undefined, which strikes me as ultimately invalid. It is usually best to name boolean variables as the "positive"; i.e. change the naming of the variable to _matchValid so that you're not doing gymnastics to understand double-negatives.

This comment was marked as abuse.

@SvetoslavTsenov
Copy link
Contributor

@VladimirAmiorkov, could you please rebase your branch on master, since there are a lot of important fixes.

@VladimirAmiorkov VladimirAmiorkov force-pushed the amiorkov/embedded-views-memory-leak-fix branch from e639a66 to 3212837 Compare October 5, 2018 06:23
@VladimirAmiorkov
Copy link
Contributor Author

@SvetoslavTsenov Yes of course. Done.

@vakrilov
Copy link
Contributor

vakrilov commented Oct 5, 2018

Hey @VladimirAmiorkov

  1. Can you elaborate a bit on what is holding a reference to the CssState in this scenario?
  2. Any ideas on how this fix can be tested so that we ensure that there are no regressions in the future.
  3. The view field is set in the constructor. It is possible that the view is loaded/unloaded multiple times. If you clear the reference in the unloaded -> that means that next time the view is loaded again it the CSSState associated to it will not work as expected. You should either set the view again in loaded or clear the view field when you are sure the view will no longer be loaded again.

@VladimirAmiorkov
Copy link
Contributor Author

VladimirAmiorkov commented Oct 5, 2018

@vakrilov

I noticed a couple of other things that could be a source of this memory leak. I will investigate them now and get back at you.

@VladimirAmiorkov
Copy link
Contributor Author

VladimirAmiorkov commented Oct 8, 2018

Hi @vakrilov ,

After researching this issue today I am unable to observe it even without any fixes in the tns-core-modules. Currently the only fixes that are required for this issue are this PR in nativescript-angular and an fix in the nativescript-ui-listview. It is very odd that last week while working on this I was able to observe the CssState in the retainers chain but today I am no longer able to observe the same. The CssState was in the retainers chain but its start was somewhere inside the core.js of Angular itself so it is possible something from Angular was the cause that has been resolved, I do hope that the Chrome Dev tools Snapshot/profiling is not misguiding us on this.

I suggest we close this PR for now since I can no longer observe an memory leak when working with the latest version (^4.2.1) of tns-core-modules and/or with the next version.

@VladimirAmiorkov
Copy link
Contributor Author

VladimirAmiorkov commented Oct 8, 2018

On a side note:

It may be nothing but I noticed that in the CssState class we are subscribing to one event here and unsubscribing from a different one here, meaning we subscribe to (attribute)Change but unsubscribe from onPropertyChanged:(attribute). This looks strange but I was not able to test it to see if it could lead to some sort of leak. If you know how I could test this part of the code let me know.

@lock
Copy link

lock bot commented Oct 11, 2019

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.

@lock lock bot locked and limited conversation to collaborators Oct 11, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants