views:

41

answers:

1

Hello everyone,

I have created a small application that, basically, exists in the system tray and the user only needs to open the actual application in VERY few cases. The problem is, that once the suer opened the application for the first time, the memory is filled up with an awful lot of data (WPF UI for datagrids, treeviews etc). But then the user will minimise the application again and it will sit there for most of the time. The only UI that is always accessible is the tray icon's contextmenu.

So here is the thing: How can I dispose of the WHOLE UI every time the application is minimised? I have tried several things in WPF but I can never get rid of the UI objects as WPF keeps references to them.

What I would love is: Open application (UI loaded) --> Minimise to tray --> Whole UI disposed and the only memory left is that used by the business logic... Next time application is opened from the tray: Whole UI is rebuilt.

Thank you very much in advance!

A: 

I suppose you could have a hidden main window and when it gets restored from the tray it will open Window2 that will contain the WHOLE UI, when you minimize the app, Window2 can be closed (thus disposed). Or maybe it's possible to open Window2 directly when doubleclicking the tray icon or via the context menu...

But this still might not give the desired result, because the Garbage Collector usually doesn't bother with collecting garbage unless there is pressure on the memory subsystem (eg you are running out of free memory).

Although I have seen the garbage collector (or maybe it's a Windows feature) paging out most of the app to the swap file when it's minimized. But I haven't looked deeply into this so I can't say what or when exactly causes this.

Marko