Possible Duplicate:
Proper stack and heap usage in C++?
Heap vs Stack allocation
I'm trying to understand why a Library I ported from Java to C++ (long and arduous editing work after using a converter) doesn't free up memory and just explodes the Virtual Memory till crash. Obviously this has to do with Java having a GC and C++ not - and the algorithms are pretty straight converted to C++.
So here's my question. Where and how do I delete allocated memory (Free it)? When I have:
Matrix *mat = new Matrix(args);
I obviously need to end the scope with a delete mat;
. Can I avoid this?
Would using Matrix mat(args);
be better? in terms of Memory Allocation and freeing?
Or using Matrix mat = Matrix(args)
?