According to this article on Diagnosing memory issues with the new Memory Usage Tool in Visual Studio:
1. Memory caps on Phone devices: In particular for Phone, there are specific memory limits enforced on an application based on the size of the memory in the device. Allocating more than the specified limit will cause an OutOfMemoryException and will result in app termination.
All well and good, and in Visual Studio you can use the Diagnostics tool to see memory usage during development.
Is there any way a UWP app running on a (Windows 10) phone can get an approximate idea of how much memory it's consuming? - I.e. within the app, not by leveraging visual studio.
Update - How I chose the 'Answer'
The key thing is that this has exposed a massive lack of understanding on my part regarding memory in general, and specifically how modern .net apps consume it. Both of these answers were of help to me, and even though I have experimented briefly with both its hard to say either one of them is the right answer as I'm finding both of them useful.
Also whilst I appreciate both the answers linking to the appropriate official documentation, that information is pretty thin (no disrespect to Romasz & Alexej).
In the end I've awarded the Answer to Romasz as the API seems a little deeper.
Check Computer Memory Usage Easily To open up Resource Monitor, press Windows Key + R and type resmon into the search box. Resource Monitor will tell you exactly how much RAM is being used, what is using it, and allow you to sort the list of apps using it by several different categories.
Try this: Open the task manager, go to the processes tab, go to view, select collums and check the box that says VM size. Notice that when you minimize or restore a program or application the memory changes from what's in Memory Usage to VM size.
I think you can also make use of MemoryManager class. There you can subscribe to events informing about increase/decrease of memory, set limits, as well as check memory usage of app or read reports for app or for process:
var appMemory = MemoryManager.AppMemoryUsage;
var appMemoryReport = MemoryManager.GetAppMemoryReport();
var processMemoryReport = MemoryManager.GetProcessMemoryReport();
For UWP apps there is ProcessDiagnosticInfo class available.
ProcessMemoryUsageReport mu = ProcessDiagnosticInfo.GetForCurrentProcess().MemoryUsage.GetReport();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With