<p>I've used the CF <a href="http://blogs.msdn.com/stevenpr/archive/2006/04/17/577636.aspx" rel="nofollow noreferrer">Remote Performance Monitor</a>, however this seems to only track memory initialised in the managed world as opposed to the unmanaged world. Well, I can only presume this as the numbers listed in the profiler are way short of the maximum allowed (32mb on CE 5). Profiling a particular app with the RPM showed me that the total usage of all the caches only manages to get to about 12mb and then slowly shrinks as (I assume) something unmanaged starts to claim more memory.
The memory slider in System also shows that the device is very short on memory. If I kill the process the slider shows all the memory coming back. So it must (?) be this managed process that is swallowing the memory.</p>

<p>Is there any simple(ish?) fashion how one can track unmanaged memory usage in some way that might enable me to match it up with the corresponding P/Invoke calls?</p>

<p><strong>EDIT: To all you re-taggers it isn't .NET</strong>, tagging the question like this confuses things. It's .NETCF / Compact Framework. I know they appear to be similar but they're different because .NET rocks whereas CF is basically just a wrapper around NotImplementedException.</p>

[{'answer_id': 10338, 'author': 'Adam Haile', 'author_id': 194, 'author_profile': 'https://Stackoverflow.com/users/194', 'pm_score': 3, 'selected': True, 'text': '<p>Try enabling <a href="http://blogs.msdn.com/stevenpr/archive/2005/06/22/431612.aspx" rel="nofollow noreferrer">Interop logging</a>.</p>\n\n<p>Also, if you have access to the code of the native dll you are using, check this out: <a href="http://msdn.microsoft.com/en-us/netframework/bb630228.aspx" rel="nofollow noreferrer">http://msdn.microsoft.com/en-us/netframework/bb630228.aspx</a></p>\n'}, {'answer_id': 11257, 'author': 'Clyde', 'author_id': 945, 'author_profile': 'https://Stackoverflow.com/users/945', 'pm_score': 1, 'selected': False, 'text': '<p>I\'ve definitely been fighting with unmanaged issues in a C# managed app for a while -- it\'s not easy. </p>\n\n<p>What I\'ve found to be most helpful is to have a regular output to a text log file.  For example you can print the output of <a href="http://msdn.microsoft.com/en-us/library/aa908760.aspx" rel="nofollow noreferrer">GlobalMemoryStatus</a>  every couple of minutes along with logging every time you load a new form.  From there you can at least see that either memory gradually erodes, or a huge chunks of memory disappeared at specific times of the day.</p>\n\n<p>For us, we found a gradual memory loss all day as long as the device was being used.  From there we eventually found that the barcode scanning device was being initialized for no particular reason in our Form base class (I blame the previous developer!  :-)</p>\n\n<p>Setting up this logging may be a small hassle, but for us it paid huge dividends in the long run especially with the device in live use we can get real data, instrumentation, stack traces from exceptions, etc.</p>\n'}, {'answer_id': 143458, 'author': 'SmacL', 'author_id': 22564, 'author_profile': 'https://Stackoverflow.com/users/22564', 'pm_score': 1, 'selected': False, 'text': '<p>Ok, I\'m using C++ on CE, not C# so this may not be helpful, but...</p>\n\n<p>I use a package called <a href="http://www.entrek.com/products.htm#CodeSnitch" rel="nofollow noreferrer">Entrk toolbox</a> which monitors memory and resource usage, leaks, and exceptions under Windows CE.  Pretty much like a lightweight CE version of boundschecker.  Does the trick most times.</p>\n'}]
['https://Stackoverflow.com/questions/10309', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/1143/']