6

I'm currently working on a metro game for Windows 8 using C# and SharpDX. The project is going well, but recently there's been a need to start tracking down memory leaks and I'm not really sure where to begin.

The built in memory profiler in Visual Studio 11 doesn't work for metro apps yet, WinDBG can't seem to connect to metro apps (unless I'm using it incorrectly), and I'm having a hard time finding any information about looking at managed allocations in .NET 4.5 for metro.

Does anyone have any experience with this? Is there a good place to start looking? Has anyone had success with tools to help detect memory leaks in metro apps?

James McNellis
  • 348,265
  • 75
  • 913
  • 977
Ben Smith
  • 143
  • 2
  • 7
  • I wouldn't spend a ton of time on this just yet. Odds are good that WinRT itself has memory leaks that will be fixed before RTM. You're just going to spend a bunch of time working around temporary issues. There should be tool support by then as well. – Robert Levy Apr 03 '12 at 14:27
  • 1
    You'd better run this through the app verifier. The odds that you can get an app that uses SlimDX published through the store ought to be, well, Slim. – Hans Passant Apr 03 '12 at 14:37
  • @HansPassant - I would agree. He might want to verify that he will even be able to publish it to the store, my understand is that unless SharpDX only uses the WinRT profile, the chances of it being published are slim to none. Looking at the project page for SharpDX the "features" they list would lead you to believe it supports the WinRT profile by using the words "Metro Style" which from even Microsoft's own products simply means a certain design style. Of course as of March 30 2012 SharpDX doesn't even support Windows 8 CP. – Security Hound Apr 03 '12 at 14:40
  • So far, the nightly build of SharpDX does build and pass verification under Win8 CP's WACK suite. I understand that there may be memory leaks in some of Microsoft's own pre-RTM code, but I'm really just looking for anyway to get information about my allocations. Even System.GC.GetTotalMemory() doesn't seem to exist for metro apps. I don't want to put off my search for too long or else I worry that I'll be spending time doing this after RTM and it could hold up the project. – Ben Smith Apr 03 '12 at 14:57
  • @BenSmith - Until the Windows 8 RC is released you will have to do it the old fashion way. Determine where the leaks are, make sure you do everything the correct way, and wait until Visual Studio memory profile feature supports the WinRT profile. – Security Hound Apr 03 '12 at 15:02
  • Whoops -- looks like WinDbg actually does work with metro apps -- only in a limited manner. At least this should get me started. Thanks everyone! – Ben Smith Apr 03 '12 at 17:03
  • SharpDX is already used by at least one application in the Windows App Store, so I assume it is safe to say that application using SharpDX will be allowed. – Denis Apr 04 '12 at 03:09
  • So now we are at RTM and I can't seem to see any tools to do memory profiling and even see [articles](http://msdn.microsoft.com/en-us/library/hh974575.aspx) that seem to indicate it is not possible at all? Have you seen anything that might help to find a leak other than a divide and conquer approach? @Hans, @Robert? – Filip Skakun Aug 27 '12 at 18:11

3 Answers3

2

Looks like I could actually use WinDbg, it just wasn't working with invasive mode. My fault.

Ben Smith
  • 143
  • 2
  • 7
1

I would, at least for now, assume that the memory leaks are not caused by Metro or SharpDX.

Check this out: Memory Leaks C#

(Or just search SO for "C# memory leaks".)

Once you go through the checklist of things gleaned from the above link/search query, then move onto checking the code related to SharpDX/Metro. The best guidelines came from my mom when I was young: "Clean up after yourself when you're done playing." Dispose of objects when you're done with them, don't leave DB, file or memory streams open for longer than you need them to be. This is the cause for many people's memory leak issues, mine included.

Community
  • 1
  • 1
Derreck Dean
  • 3,708
  • 1
  • 26
  • 45
  • I've been spending some time with the usual suspects (streams, IDisposables, events), but I more looking for any tools or functions that can give me insight into what is currently allocated. Even just being able to get a list of managed allocations would be a huge help in finding the true problem areas. – Ben Smith Apr 03 '12 at 15:01
-1

I suggest you use this http://msdn.microsoft.com/en-us/magazine/jj721593.aspx. There is a lot of explanations about memory leak.

  • Instead of merely posting a link (a comment would have been better for that), you should at least point out some highlights of the techniques discussed in that article. – Tuxdude Apr 16 '13 at 22:15