locked
WinJS.Application doesn't fire onactivated event after refresh page with location.reload

    Question

  • Hi, 

    I do know this is not a common behavior in Windows 8 App development. I'm using in-page navigation too and it it works well.

    My problem is after using my app for a long time, it gets obviously slow. Yes I know it is because of the memory leak somewhere.  But it is a huge job to dig out the problem for such a big and complex system that I'm working on. A simple and effective workaround is to refresh the whole page, then everything should be restored.

    I tried to use window.location.reload to refresh the page, it works and I find the initialize code in default.js is ran again. But then, nothing happens. After app.start() is called, the event app.onactivated will never be fired.

    Any suggestions are welcome and thanks in advanced.

    cheers

    Alex


    woodhead is as woodhead does


    • Edited by Alex ZS Tuesday, September 10, 2013 10:47 AM
    Tuesday, September 10, 2013 10:46 AM

Answers

  • Hi,

    I think I finally find out why. It's because of GC. 

    It seems GC of IE really works terrible with large objects.

    In my App, I keep creating some canvas and image objects to cache the rendering results,  and then releasing them (clear the references to them) when I don't need them. After creating more than two hundreds of objects(only about 40~50 objects are used, the others are released), it gets obviously slow. According to performance analyzer, most of the CPU time are used by GC. The problem is even GC consumes so much CPU time, it doesn't do it's job, memory consumption of App keeps high and GC keeps consuming even more CPU time.

    It get obviously much better after I create an object pool to avoid creating too much objects. But in some situation, such as editing a big document or using app for a long time (even there's no many objects created), GC may suddenly jumps out and take a lot of CPU time.

    I know GC is slow and I have quite a lot experiences of fighting with GC in .Net. But IE's GC performance is still a surprise  to me.


    woodhead is as woodhead does


    Wednesday, September 18, 2013 2:05 AM

All replies

  • I am afraid that is not possible. What you are trying to do is programmatically try to close the "application" instance and re-initialize it, which is similar to shutting down the app programmatically and restarting it (which will cause certification failure).

    Why don't you look to remove the memory leaks that is causing the actual issue. You can use the JavaScript memory analyzer to figure out what is taking up a lot of memory and free up space. In Visual Studio, there is a JavaScript memory analyzer which you can use an see if you have any areas which is taking more memory and not releasing it. Please check this link that shows how you can use this: http://msdn.microsoft.com/en-us/library/windows/apps/jj819177.aspx This video from the build conference also shows how you can analyze memory issues: http://channel9.msdn.com/Events/Build/2012/3-008


    Windows Store Developer Solutions #WSDevSol || Want more solutions? See our blog, http://aka.ms/t4vuvz

    Wednesday, September 11, 2013 1:21 AM
    Moderator
  • Hi,

    Thanks for your suggestion and reply. I'll try it.

    But I still don't understand why that is not possible. I take Windows 8 App as a special browser, it is special, but it is still a browser.  I just refresh the page in the browser, not close and re-launch the browser process, why would that cause any security problem? Even the browser that works on high security level still allows refreshing.

    Could you give me more explanation? Thank you very much.

    cheers

    Alex


    woodhead is as woodhead does

    Wednesday, September 11, 2013 1:34 AM
  • Hi,

    I tried the memory analyzer and did find some leaks and got some improvements. I'm happy to get those improvements and thanks again for your suggestions. 

    But the memory usage is still too much. The problem is that it seems that most of the memory leaks are from Winjs&Windows runtime objects that will not be displayed by analyzer.

    During my test, I took three snapshots.

    Snapshot 1 gets 45.35 MB & 39323 objects  in heap, total memory usage is about 185mb;

    Snapshot 2 gets 77.98MB 43111 object  in heap, total memory usage is about 250mb

    Snapshot 3 gets 57.3MB 35419objects in heap, total memory usage is about 350mb

    What I did is just keep switching between pages, open/save documents and so on...  The opened documents when taking the snapshots are about the same size so they should use about the same amount of memory.

    You see, the memory usage is keeping increasing but the visible memory usage on heap is relatively steady. 

    Do you have more suggestions? Thank you.

    cheers

    Alex



    woodhead is as woodhead does

    Wednesday, September 11, 2013 7:39 AM
  • Hi,

    I think I finally find out why. It's because of GC. 

    It seems GC of IE really works terrible with large objects.

    In my App, I keep creating some canvas and image objects to cache the rendering results,  and then releasing them (clear the references to them) when I don't need them. After creating more than two hundreds of objects(only about 40~50 objects are used, the others are released), it gets obviously slow. According to performance analyzer, most of the CPU time are used by GC. The problem is even GC consumes so much CPU time, it doesn't do it's job, memory consumption of App keeps high and GC keeps consuming even more CPU time.

    It get obviously much better after I create an object pool to avoid creating too much objects. But in some situation, such as editing a big document or using app for a long time (even there's no many objects created), GC may suddenly jumps out and take a lot of CPU time.

    I know GC is slow and I have quite a lot experiences of fighting with GC in .Net. But IE's GC performance is still a surprise  to me.


    woodhead is as woodhead does


    Wednesday, September 18, 2013 2:05 AM