I’ve painfully learned during last few days a lot about programming in c++.
I love it 🙂
I know I should release memory – the golden “each malloc=free” or “each new=delete” rules exist now in my world, but I’m using them to rather simple objects.
What about vector ? Wherever I can, I’m using vector.clear() but that clearly isn’t enough, because I’m having huge memory leaks.
Could you guide me on how should I treat this thing?
*Edit
Thanks, your comments made me think about the alghorithm of this application and I’ll be able to eliminate the vector totally. :O
Sorry – I started explaining what is my use case here and I found out what I really need. It’s like that when you code last 3 days for 18 hours a day 😐
*Edit 2
This is crazy. By small changes in code, I’ve eliminated memory usage from 2×130 mb (constantly growing) into 2x 13,5mb, constant size. Thanks for making me think about that in another way.
Btw. such self code review got a name – anyone remember that? It’s when you ask anyone (even your mother or dog) and start explaining what’s your problem – and suddenly you solve this 5 hour problem yourself, just by trying to look at it from other point of view, or just by trying to summarize what’s it all about. I often find myself being catched on that…
The rule is that when you clear a vector of objects, the destructor of each element will be called. On the other hand, if you have a vector of pointers,
vector::clear()will not calldeleteon them, and you have to delete them yourself.So if all you have is a vector of strings, and not pointers to strings, then your memory leaks must be caused by something else.