Jump to content
  • Advertisement
Sign in to follow this  
argonaut

Memory Leak

This topic is 4474 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Heya all, I'm having trouble tracking down a leak and i'm wondering if this is the culprit. Does the following code produce a memory leak?

void main()
{
  while(true)
  {
    Foo();
  }
}

void Foo()
{
  static int *x;
  static int *y;
  // do stuff with x and y
}

Thanks in advance!

Share this post


Link to post
Share on other sites
Advertisement
No, I'm not allocating any new memory. In this example, x and y are just placeholders for some data. I went through my real code and removed the static pointers and I'm still getting a leak ... a big one too (16MB / second).

Share this post


Link to post
Share on other sites
Could be because you are creating static pointers, over and over again in that loop. Not sure, but thats the reason I think you are getting the large memory leaks.

Share this post


Link to post
Share on other sites
Quote:
Original post by Ex777
Could be because you are creating static pointers, over and over again in that loop. Not sure, but thats the reason I think you are getting the large memory leaks.


Static variables are allocated only once and last for the duration of the program. The problem is most likely in the usage of the pointers, though.

OP: have you considered using a memory leak detector? The MSVCRT has memory leak detection functions. There is also mmgr.


jfl.

Share this post


Link to post
Share on other sites
Thanks for the replies everyone! It turns out the problem was in a function called within the function which I assumed was working correctly because it didn't cause problems in other areas. Oh well, another notch in the experience belt.

The faulty function was calling D3DXCreateFontIndirect() about 60-70 times per second, leading to me losing about 16 MB per second. If I've learned anything, it's that a directX font takes about 238K to implement (if my calculations were correct).

Thanks again for the help :)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!