• 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

    • Was it too much to ask to show the icon in this article?
    • Frankly, I blame whoever is writing such articles. "A big improvement/update and/or new feature is now available to everyone! Also, use this unofficial tweak tool to enable it because it actually isn't available to you yet officially and might not in fact even be entirely ready or whatever, hence why it is perhaps not enabled for you*. But it's great and you should enable it!" I mean there's nothing wrong with sharing info about some feature you might need to enable via unofficial means, of course. It's just that these articles tend to essentially end up being two news pieces in one, and one of them tends to be a bit misleading. (*Yes, yes, the "it's a controlled rollout!" thing. Not a fan of that one either. The argument, not the actual rollout.)
    • Thank you. Will do. I read in the release notes that editor config might be at play here.
    • Actually, I think even Microsoft doesn't know how to control it
    • OpenAI is making Codex more useful in Chrome and the cloud by Pradeep Viswanathan OpenAI's Codex now has more than 5 million users, up nearly 4x from earlier this year. To further accelerate Codex's growth among developers, OpenAI today announced that it has agreed to acquire Ona, a company that builds secure cloud execution and orchestration technology for developers. Ona will enable developers to run Codex with persistent and controlled cloud infrastructure for long-running agentic workflows. Right now, most Codex execution happens locally on developers' laptops and PCs, and the agents work continuously for hours. Through Ona, OpenAI aims to make Codex agents keep working for days without being tied to a user’s local machine or an active session. This will be an important capability for enterprises that want to deploy AI agents in production while maintaining control over infrastructure, data, security boundaries, credential scope, logging, and review workflows. Like any acquisition, the deal is still subject to customary closing conditions, including regulatory approvals. Until the deal closes, OpenAI and Ona will continue to operate as separate companies. After closing, Ona’s team will join the Codex team to improve developer workflows. Alongside the Ona acquisition announcement, OpenAI today introduced a few Codex updates. Developers can now save Codex rate limit resets and use them later instead of losing them when they are not needed immediately. OpenAI is also adding a referral option where users can invite a friend to Codex and get a saved rate limit reset. OpenAI today also announced a developer mode for browser use in Chrome and the Codex in-app browser. With this mode, Codex can use the Chrome DevTools Protocol to debug web apps, inspect pages, and work more directly with browser-based development workflows. Developers can use this when they want Codex to profile JavaScript, inspect console output and network traffic, examine web page states including the DOM and applied styles, and more.
  • Recent Achievements

    • Week One Done
      davidbazooked earned a badge
      Week One Done
    • One Month Later
      Jamswaz earned a badge
      One Month Later
    • Week One Done
      Jamswaz earned a badge
      Week One Done
    • Rookie
      Marzoid went up a rank
      Rookie
    • Community Regular
      coch went up a rank
      Community Regular
  • Popular Contributors

    1. 1
      +primortal
      509
    2. 2
      PsYcHoKiLLa
      186
    3. 3
      +Edouard
      157
    4. 4
      Steven P.
      83
    5. 5
      ATLien_0
      75
  • Tell a friend

    Love Neowin? Tell a friend!