• Advertisement
  • entries
  • comments
  • views

Memory leaks

Sign in to follow this  


Been dealing with pesky little memory leaks in the editor the last couple of days. Very annoying but finally I seem to have gotten rid of it. It was a matter of mixing up memcpy and calling new[]/delete[]. I made the error of creating a class within a class (new[]) then copying content to the "super-class" using memcpy and then expecting the new[] address that I created earlier (before the memcpy) to be the same within the class... Bad mistake. I lost the address to the new[] so I had to swap them around a bit for it to work, ugh. Took the better hours of two days to figure that one out.

I also had a wrestle with the image library I'm using, FreeImage. I recently started to enlarge my npot textures to be pot sizes with the command FreeImage_Enlarge:
bmp=FreeImage_EnlargeCanvas(bmp, 0, padY, padX, 0, &paddingColor, FI_COLOR_IS_RGB_COLOR);
I found out I had been assigning the bitmap instance that I also used as an input parameter to the enlargement function. This apparently causes a memory leak. I do this enlargement because older graphic cards and some built in chips doesn't always support npot textures (laptops and notebooks). The issue was fixed by using two bitmaps.

While doing this I wish I had a decent memory leak detection tool. I haven't found any that works with Code::Blocks (only found VC++ libs). I would be interested if anyone knows if any such tool/library exists.
Sign in to follow this  

1 Comment

Recommended Comments

I've written one which should just drop in to your project. I've only tested it with Visual Studio, and the #pragma init_seg(compiler) is Visual Studio specific, but it might be of use.

Feel free to do whatever you want with it, just don't blame me if it goes wrong [smile]


Share this comment

Link to comment

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

  • Advertisement