Memory Leaks

Hello!

Got some problems with memory leaks,have no clue what im doing wrong tho.

heres the code for the main file: http://pastebin.com/hLDmpJy3

I
closed account (S6k9GNh0)
1. It's not "Strenght" and "Lenght". it's "Strength" and "Length".
2. According to what you've written in your pastie, there should be no memory leaks. We need more code in order to see the source of memory leakage.
Yeah,some awful spelling there,and even worse code :D

anywayz,here is the rest of the files:

http://rapidshare.com/files/452534673/Leaks.rar
Last edited on
If there are memory leaks there, they are caused by your exercise classes. Do you dynamically create objects inside your exercise class that you don't delete in the destructor?
No,the weird thing is that i dont alocate any new memory in the included classes,basicly just set/get fuktions+constructors.
closed account (zb0S216C)
It might not help, but have you tried setting e1 and e2 to NULL after you delete them?
@Framework That's not really related to leaking memory though.
closed account (zb0S216C)
It's worth a shot. And without the entire code, there isn't going to be any useful suggestions.
Rest of the code in one pastie,hope its not to hard to read
http://pastebin.com/qc0qRfZV


and yeah,tried what u suggested @Framework, didnt help.
closed account (zb0S216C)
Where are your destructors?
Nevermind. Something tells me that it's the inheritance that's causing it.
Last edited on
I didn't see anything that would leak (short of throwing an exception). Are you sure you're using the leak check thing right? It doesn't require another line at the end of the program?

Consider running it through valgrind.

EDIT:

...actually, you're right. You're deleting the object through a base class pointer. You need a virtual destructor to do that.
Last edited on
closed account (zb0S216C)
my compilator is telling me that memory leaks occcur

And what compiler would this be?
And what compiler would this be?

Using Microsoft Visual Studio.


...actually, you're right. You're deleting the object through a base class pointer. You need a virtual destructor to do that.


Added a virtual destructor to every class,and voila,no memory leaks!
The reason i didnt go with em in the first place,is cause i thought you didnt need a virtual destructor unless you allocate new memory in the constructor. Think i did misinterpret
that having a empty destructor=no destructor at all.

Thanks for all the replies!
,is cause i thought you didnt need a virtual destructor unless you allocate new memory in the constructor


You need a destructor when you need to free resources you have allocated (probably in the constructor)
It needs to be virtual when someone will do this:

1
2
Base* p = new Derv(some_handle);
delete p;


Since it is virtual, it will correctly call ~Derv(), if it wasn't it will only call ~Base(), thus never releasing some_handle.

Obviously this only applies if you want someone to be able to derive from your class. If you look at the STL containers, you will notice they don't have virtual destructors. That is because they aren't meant to be derived from.
Topic archived. No new replies allowed.