From 7340a6e2fc08d6c5208f03477877fd41b8a48d2d Mon Sep 17 00:00:00 2001 From: Rossen Hristov Date: Fri, 20 May 2016 17:48:34 +0300 Subject: [PATCH] Trying to prevent memory leaks. --- apps/tests/navigation/navigation-tests.ts | 19 +++++++++++++++++++ ui/frame/frame.android.ts | 6 ++++++ 2 files changed, 25 insertions(+) diff --git a/apps/tests/navigation/navigation-tests.ts b/apps/tests/navigation/navigation-tests.ts index 639a98ff5..965bb2120 100644 --- a/apps/tests/navigation/navigation-tests.ts +++ b/apps/tests/navigation/navigation-tests.ts @@ -24,6 +24,14 @@ function waitUntilNavigatedFrom(oldPage: Page) { }); } +function androidGC() { + let topmost = topmostFrame(); + if (topmost.android) { + gc(); + java.lang.System.gc(); + } +} + function _test_backstackVisible(transition?: NavigationTransition) { let topmost = topmostFrame(); let mainTestPage = topmost.currentPage; @@ -52,10 +60,12 @@ function _test_backstackVisible(transition?: NavigationTransition) { } export var test_backstackVisible = function () { + androidGC(); _test_backstackVisible(); } export var test_backstackVisible_WithTransition = function () { + androidGC(); _test_backstackVisible({name: "fade"}); } @@ -107,10 +117,12 @@ function _test_backToEntry(transition?: NavigationTransition) { } export var test_backToEntry = function () { + androidGC(); _test_backToEntry(); } export var test_backToEntry_WithTransition = function () { + androidGC(); _test_backToEntry({name: "flip"}); } @@ -159,14 +171,17 @@ function _test_ClearHistory(transition?: NavigationTransition) { // Clearing the history messes up the tests app. export var test_ClearHistory = function () { + androidGC(); _test_ClearHistory(); } export var test_ClearHistory_WithTransition = function () { + androidGC(); _test_ClearHistory({ name: "fade" }); } export var test_ClearHistory_WithTransition_WithCachePagesOnNavigate = function () { + androidGC(); let topmost = topmostFrame(); if (!topmost.android) { return; @@ -180,6 +195,7 @@ export var test_ClearHistory_WithTransition_WithCachePagesOnNavigate = function // Test case for https://github.com/NativeScript/NativeScript/issues/1948 export var test_ClearHistoryWithTransitionDoesNotBreakNavigation = function () { + androidGC(); let topmost = topmostFrame(); let mainTestPage = topmost.currentPage; let mainPageFactory = function (): Page { @@ -215,6 +231,7 @@ export var test_ClearHistoryWithTransitionDoesNotBreakNavigation = function () { } export var test_ClearHistoryWithTransitionDoesNotBreakNavigation_WithLocalTransition = function () { + androidGC(); let topmost = topmostFrame(); let originalCachePagesOnNavigate: boolean; if (topmost.android) { @@ -314,9 +331,11 @@ function _test_NavigationEvents(transition?: NavigationTransition) { } export var test_NavigationEvents = function () { + androidGC(); _test_NavigationEvents(); } export var test_NavigationEvents_WithTransition = function () { + androidGC(); _test_NavigationEvents({ name: "fade" }); } \ No newline at end of file diff --git a/ui/frame/frame.android.ts b/ui/frame/frame.android.ts index d28623641..7faac120f 100644 --- a/ui/frame/frame.android.ts +++ b/ui/frame/frame.android.ts @@ -696,7 +696,13 @@ class FragmentClass extends android.app.Fragment { trace.write(`${this}.onDestroy()`, trace.categories.NativeLifecycle); } super.onDestroy(); + this.entry.fragmentTag = undefined; + this.entry = undefined; + this.frame = undefined; + this.clearHistory = undefined; + transitionModule._clearBackwardTransitions(this); + transitionModule._clearForwardTransitions(this); } public toString(): string {