Memory leak in MemeFighter code- Intermediate 18
Memory leak in MemeFighter code- Intermediate 18
Hi All.
Anyone notice a memory leak in the MemeFighter code from I-18?
When I #include <crtdbg.h> and run _CrtDumpMemoryLeaks(); I get 4 leaked objects.
However, cuz I'm new to all this, despite #define _CRTDBG_MAP_ALLOC and redefining the 'new' operator (per a bunch of StackOverflow posts), I can't coax _CrtDumpMemoryLeaks into dumping the file and line number of the leaks, so I'm kinda stuck.
Soooooo, anyone have an insight about how to go about investigating a memory leak like this?
Thanks, M
Anyone notice a memory leak in the MemeFighter code from I-18?
When I #include <crtdbg.h> and run _CrtDumpMemoryLeaks(); I get 4 leaked objects.
However, cuz I'm new to all this, despite #define _CRTDBG_MAP_ALLOC and redefining the 'new' operator (per a bunch of StackOverflow posts), I can't coax _CrtDumpMemoryLeaks into dumping the file and line number of the leaks, so I'm kinda stuck.
Soooooo, anyone have an insight about how to go about investigating a memory leak like this?
Thanks, M
-
- Posts: 4373
- Joined: February 28th, 2013, 3:23 am
- Location: Oklahoma, United States
Re: Memory leak in MemeFighter code- Intermediate 18
Post your project, perhaps that would bee a better option than shots in the dark.
Best way would be to use GitHub, if you followed chili's videos.
Best way would be to use GitHub, if you followed chili's videos.
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com
Re: Memory leak in MemeFighter code- Intermediate 18
Not really shots in the dark-- just added that to the master branch of chili's repo. But gimme a sec and I'll share my repo.
-
- Posts: 4373
- Joined: February 28th, 2013, 3:23 am
- Location: Oklahoma, United States
Re: Memory leak in MemeFighter code- Intermediate 18
Nope, not a leak. The t1 and t2 vectors are still "alive" when _CrtDumpMemoryLeaks() is called. Put lines 315 - 372 inside curly braces {} and the two vectors "die" at the } online 372 and no dump is output to the console.
The way I was able to get that is the output showed the pointers that were still alive. Then I checked the addresses of t1 and t2 and t1 had an address that was pretty close ( within 64 bytes ) so I just enclosed in {} and no more mem leak dump.
This approach would be impossible to do in a larger project. I had this issue with some global smart pointers, and it took quite some time to track down the culprits.
The way I was able to get that is the output showed the pointers that were still alive. Then I checked the addresses of t1 and t2 and t1 had an address that was pretty close ( within 64 bytes ) so I just enclosed in {} and no more mem leak dump.
This approach would be impossible to do in a larger project. I had this issue with some global smart pointers, and it took quite some time to track down the culprits.
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com
Re: Memory leak in MemeFighter code- Intermediate 18
Wow, yeah: braces = scope. Duh. Thanks Albi.
The address of the allocator for the t1 vector was exactly the one ref'd in _CrtDumpMemoryLeaks()!
But wait, are vectors allocated in the stack or the heap?
Also, dumb question: how do I add a screencap to these posts?
Thx, M
The address of the allocator for the t1 vector was exactly the one ref'd in _CrtDumpMemoryLeaks()!
But wait, are vectors allocated in the stack or the heap?
Also, dumb question: how do I add a screencap to these posts?
Thx, M
Re: Memory leak in MemeFighter code- Intermediate 18
The elements of a vector are stored on the heap
Re: Memory leak in MemeFighter code- Intermediate 18
I needs me a red pill baby.
-
- Posts: 4373
- Joined: February 28th, 2013, 3:23 am
- Location: Oklahoma, United States
Re: Memory leak in MemeFighter code- Intermediate 18
Yeah, vector can be implemented as a base pointer and end pointer where size is ( end - begin ) / sizeof(T) and a reserved or capacity variable to determine when the container needs to grow. It can also be implemented as a base pointer with a size and reserved or capacity variables. The base pointer and end pointer and the capacity value are stored on the stack or base pointer and size and capacity values are stored on the stack, but as Yumtard said, the base/end pointers point to a location on the heap.
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com
Re: Memory leak in MemeFighter code- Intermediate 18
I have been accused of leaking memory??!
Who dares besmirch the good name of ChiliTomatoNoodle??! D:<
Who dares besmirch the good name of ChiliTomatoNoodle??! D:<
Chili