• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
Crusable77

std::vector memory leak issues

12 posts in this topic

Hello, I have an entity with a std::vector<Component*> m_components (Component is an abstract base class all other Components inherit from so I can polymorph them) and when I destroy the entity I clear the vector like so:

Entity::~Entity(){
	for(std::vector<Component*>::iterator iter = m_components.begin(); iter != m_components.end(); ++iter){
		delete *iter;
		*iter = NULL;
	}
	m_components.clear();
	m_components.shrink_to_fit();
} 

and I get memory leaks. I looked online and everywhere I look it looks like I am doing it right. The memory leaks are a jumble of numbers:

Detected memory leaks!
Dumping objects ->
{377} normal block at 0x05804D28, 8 bytes long.
 Data: < N      > 90 4E 80 05 00 00 00 00 
{376} normal block at 0x05804E80, 80 bytes long.
 Data: <  c   w   c     > 90 B1 63 05 D8 81 77 05 90 B1 63 05 00 00 CD CD 
{374} normal block at 0x05884028, 98304 bytes long.
 Data: <                > 00 00 FF FF 00 00 FF FF 00 00 FF FF 00 00 FF FF 
{373} normal block at 0x05804E38, 8 bytes long.
 Data: < M      > A4 4D 80 05 00 00 00 00 
{372} normal block at 0x05804DF0, 8 bytes long.
 Data: < M      > 80 4D 80 05 00 00 00 00 
{371} normal block at 0x05804D70, 68 bytes long.
 Data: <  c   w   c     > C8 B0 63 05 C8 80 77 05 C8 B0 63 05 00 00 CD CD 
{353} normal block at 0x05778268, 8 bytes long.
 Data: <  w     > E8 81 77 05 00 00 00 00 
{352} normal block at 0x057781D8, 80 bytes long.
 Data: <  c  *x  N      > 90 B1 63 05 10 2A 78 05 80 4E 80 05 01 00 CD CD 
{350} normal block at 0x057839A0, 262144 bytes long.
 Data: < $   $   $   $  > 83 24 0C FF 83 24 0C FF 83 24 0C FF 83 24 0C FF 
{349} normal block at 0x05778190, 8 bytes long.
 Data: <  w     > FC 80 77 05 00 00 00 00 
{348} normal block at 0x05778148, 8 bytes long.
 Data: <  w     > D8 80 77 05 00 00 00 00 
{347} normal block at 0x057780C8, 68 bytes long.
 Data: <  c   x pM      > C8 B0 63 05 08 19 78 05 70 4D 80 05 01 00 CD CD 
{326} normal block at 0x05772908, 8 bytes long.
 Data: < *x     > 20 2A 78 05 00 00 00 00 
{325} normal block at 0x05782A10, 80 bytes long.
 Data: < &w   c   w     > 18 26 77 05 90 B1 63 05 D8 81 77 05 01 00 CD CD 
{323} normal block at 0x057819D0, 4096 bytes long.
 Data: <                > FF 00 00 FF FF 00 00 FF FF 00 00 FF FF 00 00 FF 
{322} normal block at 0x05781988, 8 bytes long.
 Data: << x     > 3C 19 78 05 00 00 00 00 
{321} normal block at 0x05772950, 8 bytes long.
 Data: <  x     > 18 19 78 05 00 00 00 00 
{320} normal block at 0x05781908, 68 bytes long.
 Data: <@"w   c   w     > 40 22 77 05 C8 B0 63 05 C8 80 77 05 01 00 CD CD 
{303} normal block at 0x0577A100, 8 bytes long.
 Data: <(&w     > 28 26 77 05 00 00 00 00 
{302} normal block at 0x05772618, 80 bytes long.
 Data: <  c  *x   c     > 90 B1 63 05 10 2A 78 05 90 B1 63 05 01 00 CD CD 
{299} normal block at 0x05779030, 4096 bytes long.
 Data: <                > FF 00 00 FF FF 00 00 FF FF 00 00 FF FF 00 00 FF 
{298} normal block at 0x05772308, 8 bytes long.
 Data: <t"w     > 74 22 77 05 00 00 00 00 
{297} normal block at 0x057722C0, 8 bytes long.
 Data: <P"w     > 50 22 77 05 00 00 00 00 
{296} normal block at 0x05772240, 68 bytes long.
 Data: <  c   x   c     > C8 B0 63 05 08 19 78 05 C8 B0 63 05 01 00 CD CD 
{275} normal block at 0x0563B220, 8 bytes long.
 Data: <| c     > 7C B0 63 05 00 00 00 00 
{274} normal block at 0x0563B190, 80 bytes long.
 Data: < &w  *x  N      > 18 26 77 05 10 2A 78 05 80 4E 80 05 01 01 CD CD 
{273} normal block at 0x0563B148, 8 bytes long.
 Data: <p c     > 70 B0 63 05 00 00 00 00 
{272} normal block at 0x0563B0C8, 68 bytes long.
 Data: <@"w   x pM      > 40 22 77 05 08 19 78 05 70 4D 80 05 01 01 CD CD 
{271} normal block at 0x0563B070, 24 bytes long.
 Data: <H c   c       c > 48 B1 63 05 C8 B0 63 05 04 00 00 00 20 B2 63 05 
{171} normal block at 0x0357F378, 40 bytes long.
 Data: <  5_            > D4 C5 35 5F 18 00 00 00 08 00 00 00 00 00 00 00 
{170} normal block at 0x003FBFE8, 40 bytes long.
 Data: <  5_            > D4 C5 35 5F 18 00 00 00 08 00 00 00 00 00 00 00 
Object dump complete.

I am using VS2012's built in system for detecting memory leaks. This is the only place I am dynamically allocating anything in my program and when I comment out everything that has to do with the vector I get no errors. Thanks for any help.

0

Share this post


Link to post
Share on other sites

Hello, I did  #define _CRTDBG_MAP_ALLOC and my destructors are virtual:

/*Component is the parent to all other components
so the entity class can have a std::vector<Componet*>*/

#ifndef COMPONENT_HPP
#define COMPONENT_HPP

class Component{
public:
	Component();
	virtual ~Component() = 0;
	virtual void update(float deltaT);
};

#endif //COMPONENT_HPP
Edited by Crusable
0

Share this post


Link to post
Share on other sites

Dude, read the MSDN article, it will tell exactly how to debug memory leaks, including pinpointing and breaking on the allocation.

0

Share this post


Link to post
Share on other sites

There's a section there on how to interpret the leaking allocation number, and how to break on those when the allocations are made. Did you try using it?

0

Share this post


Link to post
Share on other sites

The bigger question is whether or not the class being delete is also allocating memory. Also like mentioned before, you should be deleting reference to the concrete instances and not the base class.

0

Share this post


Link to post
Share on other sites

Also, you need to understand about how std::allocator works as a caching pool allocator that may (depending on the implementation) use memory of dynamic storage duration which is freed after return from main() or possibly not at all.  This is by design.  That means that it may be normal to see what appear to be leaks when using containers from the standard library, especially if you're not using the right tools or not using the tools right.

0

Share this post


Link to post
Share on other sites

Do what N.I.B. says. (+1)

 

You're vector delete code looks ok to me (making sure Components and derived classes have a virtual destructor). So I have to ask if it's plugged in?

 

Are you dynamically allocating any Entity's? If so, you'll need to delete them obviously. Put a break point in your destructor to be sure it's getting called. 

 

Plus any components that new up any objects, need to delete those as well.

 

- Eck

0

Share this post


Link to post
Share on other sites

Here's something else you can do: Reduce your program to the simplest possible program that still shows a leak. Just make a copy of your code and start taking out anything that doesn't have to do with the problem at hand. You'll get to a point where anything you remove will stop showing the problem. We'll call that a "minimal program".

 

In the process of finding that minimal program, you'll very often figure out the problem yourself. And if you don't, you can always post the program here (it shouldn't be more than 40 lines) and you'll get much better help.

 

This is a general procedure that works for many types of bugs.

1

Share this post


Link to post
Share on other sites

Thank you everyone. I figured out the error was with my singleton, it wasn't deleting properly. Thanks for the help.

1

Share this post


Link to post
Share on other sites

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  
Followers 0