Sign in to follow this  

Memory Leak

This topic is 4106 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
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
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

This topic is 4106 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this