memory leak somewhere

Started by
14 comments, last by blaze02 18 years, 1 month ago
Running my prog in debug mode works fine without error or warning. When I run the program in release, however, this msg comes up. It appears right after the client connects to another client. First-chance exception at 0x71a92413 in Shooter.exe: 0xC0000005: Access violation writing location 0x00130000. First-chance exception at 0x00409869 in Shooter.exe: 0xC0000005: Access violation reading location 0x00000002. Then it repeats this until the program is exited: First-chance exception at 0x00000000 in Shooter.exe: 0xC0000005: Access violation reading location 0x00000000. The memory leak is getting detected, but its not giving me any indication as to where it is. I know there are libraries in the compiler that may be able to help me, can anybody point me towards those functions? When it attempts to read from location 0x00000002, I'm assuming that is my structure with 2 shorts; pretty much the only time I'm reading from a memory address that is not divisible by 4. Any suggestions? Why would running debug mode not detect this memory leak?
-------Harmotion - Free 1v1 top-down shooter!Double Jump StudiosBlog
Advertisement
The typical problem when switching from Debug to Release is that variables don't automatically get initialised to zero in release.

Check for this. Hope that helps,

Dave
...which is why now is a good time to crank up compiler warnings to the strictest setting :)
I always have compiler warnings on the highest level. It will warn if there is a chance something is not initialized before use, plus there are run-time checks to make sure variables are getting set before they are used.
-------Harmotion - Free 1v1 top-down shooter!Double Jump StudiosBlog
Turn "Generate Debug Info" on for your release build. This will help give you more useful info in the debugger when it does in fact crash.
Quote:Original post by davidlkoenig
Turn "Generate Debug Info" on for your release build. This will help give you more useful info in the debugger when it does in fact crash.


It was on, thats why it was generating the errors in the first place.
-------Harmotion - Free 1v1 top-down shooter!Double Jump StudiosBlog
BTW, these are not memory leaks. A memory leak happens when you are unable to deallocate (and reuse) memory, usually because the pointer to the allocation is overwritten. Here is a simple example of a memory leak:
    int * pAlloc = new int[ 1048576 ]; // A 4MB allocation    pAlloc = &some_other_int;          // The allocation is now "leaked"        // At this point, the address of the allocation is lost, and so the memory can    // never be deallocated and reused. 
The problem you are having is dereferencing an invalid pointer. The usual reasons are:
  • referencing deallocated memory,
  • dereferencing an uninitialized pointer,
  • bad pointer arithmetic,
  • dereferencing a pointer that has been set to 0 (to indicate that the memory was deallocated),
  • dereferencing a pointer parameter whose value is 0, and
  • this == 0.
John BoltonLocomotive Games (THQ)Current Project: Destroy All Humans (Wii). IN STORES NOW!
You can use the CRT debugging functions. However these are reserved for _DEBUG builds.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclib/html/_crt_debug_functions.asp

If you're using DirectX in your app, you can turn on "Break on memory errors" through the DirectX applet in control panel. Make sure you're running the debug directx runtimes as well.
Try using the Fluid Studios memory manager. It can detect memory leaks and keeps track of all memory allocations, and it may be able to detect your memory problems. Its also extremly easy to use: just include the headers.
Fluid Studios Memory Manager
Mike Popoloski | Journal | SlimDX
Quote:Original post by ussnewjersey4
Try using the Fluid Studios memory manager. It can detect memory leaks and keeps track of all memory allocations, and it may be able to detect your memory problems. Its also extremly easy to use: just include the headers.
Fluid Studios Memory Manager


I'm looking into that now. I don't see it helping me much because I don't create memory dynamically too often. And I don't use _alloca() anymore. I'm assuming my problem is some bad ptr math, but I don't see where, and I don't see why it wouldn't cause a problem in debug mode.

Yeah, I know it is not exactly a leak. Its most likely me derefencing null memory somehow.
-------Harmotion - Free 1v1 top-down shooter!Double Jump StudiosBlog

This topic is closed to new replies.

Advertisement