I’m integrating unity webgl inside an AngularJS app and to clear the memory I simply reload the page when exiting a tab running Unity. I know I loose the advantage of the “one page” but this also allows me to run different Unity instances inside the web app.
In Angular I add a listener on routeChangeSuccess (Which is fired when changing tab) at the beginning of my component controller :
[...]
$rootScope.$on('$routeChangeSuccess', function(angularEvent, current, previous){
//Avoids reloading when staying on the same route
if(current.$route.originalPath != previous.$route.originalPath){
$window.location.reload();
}
});
[...]
I guess there is something like this too in Angular.
Not quite. This is the problem with Single Page Applications - they do not reload window. In our case reload will take a user back to login page.
We need a solution without page reloading or reloading inside an IFrame.
At the moment the only way to unload the gameInstance and release memory is by using an iframe, then releasing all references to the iframe when you need it to be unloaded.
It should be possible to do it without using an iframe but this is not working properly at the moment. It’s something we need to fix. Here is the public bug tracker to a related problem.
I’ll stop looking for a workaround then - although my previous PWA app used a router so that I was able to do a page re-load without redirecting to the homepage.