7

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.

Adrian K
  • 9,880
  • 3
  • 33
  • 59

2 Answers2

9

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();
Romasz
  • 29,662
  • 13
  • 79
  • 154
6

For UWP apps there is ProcessDiagnosticInfo class available.

ProcessMemoryUsageReport mu = ProcessDiagnosticInfo.GetForCurrentProcess().MemoryUsage.GetReport();
Alexej Sommer
  • 2,677
  • 1
  • 14
  • 25