• 0

C++ Visual Studio 2010 Memory Leak Tracking


Question

I am writing a game in C++ using SDL as the main library, and everything seems to be going okay. However I am noticing large memory usage when I load in a texture, and freeing up pointers/objects with delete() doesn't seem to be actually freeing up memory. So on linux I used ValGrind but I find it difficult to understand where my problems are happening.

I copied my code over and have it compiling and running under Windows using Visual Studio 2010 Pro. I notice the memory usage is the same on both windows and linux, and the memory use doesn't rise constantly but it does rise when objects are created (normal), however before creation is should be deleting the one previously taking that memory space (not freeing), and using some couts I can see that it is freeing them.

ie)

MyObject *obj = new MyObject() // results in + 200kb used

delete(obj) // Doesn't reduce memory by 200kb

obj = NULL // Just sets the pointer to null

If I kept running that my memory would constantly grow by 200kb (which I think is far more than that object should be using anyways). So to try and figure out what was going on I tried adding in the leak code as stated by MS on MSDN.

http://msdn.microsoft.com/en-us/library/e5ewb1h3(v=vs.80).aspx

I put that in my main.cpp file and put the "_CrtDumpMemoryLeaks();" in my main function which looks like


int main(int argc,char[] argv)
{
_putenv("SDL_CENTER_WINDOW");
AttikClient::StartGame();
_CrtDumpMemoryLeaks();
return 0;
}
[/CODE]

AttikClient::StartGame() initializes a static function in a static class, that has the main game loop and other logic. However when I close my program there is no leak output in the output window. I have debug on as I can step through the code and can see basic output but no leak information.

I have also tried VLD (Visual Leak Detector) http://www.codeproject.com/Articles/9815/Visual-Leak-Detector-Enhanced-Memory-Leak-Detectio

And got the same results. The build mode is for sure set as debug, and I make sure to do F5 which is Debug Application. Am I missing something?

8 answers to this question

Recommended Posts

  • 0

I'm no programmer, but a quick search on google returned this: http://stackoverflow.com/questions/2153776/how-to-use-crtdumpmemoryleaks

It says you need to tell the software where to display messages. And since you're software already says "return 0;" I'm guessing you won't even get the "1" value for leaks, and "0" for no leaks.

  • 0

I found the problem kindof.

I needed to set the Runtime Environment to be /MDd instead of /MD which will enable _DEBUG. Now I can see some memory leaks, however I copied the code from MS and I still don't see a file name for where the leak occured. I defined everything that it says to.

Also, now when I try the VLD I just get an Application Failed To Start crash.

Okay. This thread can be closed, I found the issue with VLD (was missing 2 files). All seems to be working :D

  • 0

There's your memory leak :laugh:

Was originally going to do it in XNA/C# however I wanted to make it cross platform without having to do major re-writes. At this point the only changes to go from linux to windows is a third part pthread class, and a couple different libs for networking.

  • 0

Was originally going to do it in XNA/C# however I wanted to make it cross platform without having to do major re-writes. At this point the only changes to go from linux to windows is a third part pthread class, and a couple different libs for networking.

Have you considered MonoGame? If anything you should have even less code differences between platforms going .NET/MonoGame than C++/SDL. No need for different libraries for threading and networking, for instance, as that's standard in .NET.
  • 0

Have you considered MonoGame? If anything you should have even less code differences between platforms going .NET/MonoGame than C++/SDL. No need for different libraries for threading and networking, for instance, as that's standard in .NET.

I had considered it. However the C++ also serves the dual purpose of teaching me C++. I am proficient in C#/VB/PHP so I figure I might as well learn C++ syntax as well.

This topic is now closed to further replies.
  • Posts

    • Windows 11 gets useful new File Explorer features in the latest build by Taras Buria Friday Windows 11 preview builds are finally here. After skipping one week, Microsoft is back to releasing preview builds for Windows Insiders to try. This time, Insiders in the Experimental Channel can download build 26300.8687. Its changelog does not contain anything major, but there is still useful new stuff, such as some new conveniences for File Explorer, Windows Update improvements, better Windows Search, a new search provider for the built-in GIF library, and more. Here is the changelog: [Windows Update] As announced in the Windows Update announcement blog, we are now bringing a new unified update experience to reduce the number of reboots you see per month. We are starting by coordinating driver, .NET, and firmware updates to align with the monthly quality update, reducing the update experience to a single monthly restart. See the blog for more information. [File Explorer] Middle-click to open a folder in a new tab is now supported in the Address Bar and the Home page for a more consistent and efficient tabbed navigation experience across File Explorer. Improved screen reader announcements for conflict resolution dialog ("Which files do you want to keep?") when moving/copying files. Made some more improvements to how File Explorer responds to increased text scaling. [Search] Finding apps is more forgiving. Search is better at handling typos, dropped letters, extra letters, and partial words for apps. Queries like “utlook” can still find Outlook. Settings results are improving. We’ve made ranking improvements to help more relevant settings appear higher in results. [Taskbar] Improved reliability of loading the system tray area of the taskbar. Fixed an issue where tooltips might unexpectedly appear on top of the Start menu icon in the taskbar when using the taskbar in an alternate position. Also fixed a few other visual polish issues when using the taskbar with small icons. [Windows setup] The digital safety of users and supporting families is central to how we think about the Windows experience. We're improving information on parental controls and their availability during Windows setup, so families can more easily understand available protections and make informed choices from the very beginning. [Input] Update: The emoji panel (Windows key + period (.)) now uses GIPHY as the GIF provider, delivering a smoother GIF browsing and sharing experience following the deprecation of Tenor. Fixed an issue that was causing the mouse cursor to potentially move in the wrong direction in recent Insider builds on secondary monitors when set to portrait mode. [Remote Recovery Management] Adding a recovery remote management plug-in for extending WinRE management capabilities for MDM providers [Audio] Fixed an issue resulting in audio not working for some Insiders after the latest flights. [Settings] Fixed an issue impacting the reliability of Settings > Apps > Installed Apps after the latest flights. [General Reliability] If you were experiencing freezes in the previous flight when interacting with search, Notepad, or certain other scenarios, that should be resolved now. [Other] When using dark mode, if you open "Run new task" from Task Manager, it will now show in dark mode too. As usual, changes above are rolling out gradually. You can find the release notes here in the official documentation.
    • Im in Ohio, and my VPN endpoint is in Boston. If that helps, it does happen both on and off the VPN. and again only in Edge.
    • It is such a shame. I used to really respect Neowin's articles.
    • So.... slower fixes and slower security updates are preferred? I mean, there is no goldilocks zone here until it can literally update without ever needing a restart, and even then I'm sure someone would complain.
  • Recent Achievements

    • One Month Later
      Clizby earned a badge
      One Month Later
    • One Month Later
      Timaximus earned a badge
      One Month Later
    • Week One Done
      Timaximus earned a badge
      Week One Done
    • Rookie
      FBSPL went up a rank
      Rookie
    • First Post
      davidbazooked earned a badge
      First Post
  • Popular Contributors

    1. 1
      +primortal
      490
    2. 2
      PsYcHoKiLLa
      168
    3. 3
      +Edouard
      163
    4. 4
      Steven P.
      85
    5. 5
      ATLien_0
      76
  • Tell a friend

    Love Neowin? Tell a friend!