-
-
Notifications
You must be signed in to change notification settings - Fork 241
Potentiel leak: NativeScript views not cleaned up on removal #1738
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I've been playing around trying to clear some of this up in this branch: But the changes should be cleared up before I make a PR and I could use some input :) |
I think, I found a better example: If you run this app in debug mode on android and tap "Start flipping listviews" it will flip between two listviews. The memory usage will keep increasing and the number of If I run the same test with my changes from: https://github.com/m-abs/nativescript-angular/tree/fix/view-utils-hieraki-not-cleaned-up |
Doesn't look like However I get a lot of let over Labels as described here: NativeScript/NativeScript#6913 |
Environment
Provide version numbers for the following components (information can be retrieved by running
tns info
in your project folder or by inspecting thepackage.json
of the project):Describe the bug
While working on #1728 I think I’ve found a couple of memory leaks in nativescript-angular.
ListViewComponent/TemplatedItemsComponent items.
In onItemLoading(args) https://github.com/NativeScript/nativescript-angular/blob/master/nativescript-angular/directives/templated-items-comp.ts#L141-L181
TheviewRef
is bound to theargs.view[NG_VIEW]
.This is never cleared, so when theListViewComponent
is destroyed this reference still exists.I suggest making this a
WeakRef
.The factory functions in TemplatedItemsComponent._templateMap creates a circular reference and should be cleared in
ngOnDestroy()
NativeScript views lives on after the angular app have been destroyed.
The native views are destroyed as expected but according to the Chrome debugger the NativeScript views lives on.
This is caused by the AppHostView not being cleared up on exit and the
firstChild
,lastChild
andnextSibling
references are not cleaned up.The AppHostView is reused on next launch, so it shouldn’t itself be deleted but the children should.
Sidenote: AppHostView._ngAppRoot is a reference to the last Frame even after exit, this should be solved by deleting all its children on exit.
ViewUtils.removeChild(parent, child) doesn’t remove children recursively.
ViewUtils sets up the
firstChild
,lastChild
andnextSibling
references when a view is added, but doesn’t clear them up properly when a parent view is removes.I suggest making removeFromQueue(parent, child) and removeFromVisualTree(parent, child) recursive to clear up the references.
PageRouterOutlet doesn’t clear up it’s children.
this.activated
should be destroyed inngOnDestroy()
NSLocationStrategy don’t have an ngOnDestroy()
This leaves
correntOutlet
with a reference to the destroyedPageRouterOutlet
.To Reproduce
tns create --ng NAME
Frame'/
ActionBar/
Page/
PageRouterOutlet, N*8
StackLayout` etc. The native views will have been destroyed.firstChild
,lastChild
andnextSibling
Note: It doesn't seem to matter how many times I call
GC()
or how long I wait.Expected behavior
GC()
to have collected the NativeScript Views.Sample project
https://github.com/m-abs/tns-ng-app-lifecycle
Additional context
The text was updated successfully, but these errors were encountered: