Register    Login    Forum    Search    FAQ

Board index » Everything




Post new topic Reply to topic  [ 11 posts ]  Go to page 1, 2  Next
Author Message
 Post Posted: December 29th, 2017, 10:59 pm 
 

Joined: December 8th, 2017, 8:48 pm
Posts: 10
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


Top 
 Profile  
Reply with quote  
 Post Posted: December 30th, 2017, 1:46 am 
 

Joined: February 28th, 2013, 3:23 am
Posts: 2908
Location: Oklahoma, United States
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.

_________________
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


Top 
 Profile  
Reply with quote  
 Post Posted: December 30th, 2017, 2:33 am 
 

Joined: December 8th, 2017, 8:48 pm
Posts: 10
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.


Top 
 Profile  
Reply with quote  
 Post Posted: December 30th, 2017, 2:51 am 
 

Joined: December 8th, 2017, 8:48 pm
Posts: 10
Here's my repo with the <crtdbg.h> code added:

https://github.com/MCanterel/Inheritance.git


Top 
 Profile  
Reply with quote  
 Post Posted: December 30th, 2017, 12:30 pm 
 

Joined: February 28th, 2013, 3:23 am
Posts: 2908
Location: Oklahoma, United States
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.

_________________
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


Top 
 Profile  
Reply with quote  
 Post Posted: December 30th, 2017, 4:26 pm 
 

Joined: December 8th, 2017, 8:48 pm
Posts: 10
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


Top 
 Profile  
Reply with quote  
 Post Posted: December 30th, 2017, 5:43 pm 
User avatar

Joined: January 19th, 2017, 10:28 pm
Posts: 509
Location: Idiot from northern Europe
The elements of a vector are stored on the heap

_________________
I just like to thumb my nose at millionaires.
If I was rolled I'd bust them heads up.


Top 
 Profile  
Reply with quote  
 Post Posted: December 30th, 2017, 7:55 pm 
 

Joined: December 8th, 2017, 8:48 pm
Posts: 10
I needs me a red pill baby.


Top 
 Profile  
Reply with quote  
 Post Posted: December 31st, 2017, 6:13 am 
 

Joined: February 28th, 2013, 3:23 am
Posts: 2908
Location: Oklahoma, United States
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


Top 
 Profile  
Reply with quote  
 Post Posted: December 31st, 2017, 8:40 pm 
Site Admin
User avatar

Joined: December 31st, 2011, 4:53 pm
Posts: 3514
Location: Japan
I have been accused of leaking memory??!

Who dares besmirch the good name of ChiliTomatoNoodle??! D:<

_________________
Chili


Top 
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
 
Post new topic Reply to topic  [ 11 posts ]  Go to page 1, 2  Next

Board index » Everything


 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
cron