Hello fellow programmers,
I thought I had the basic stuff covered and started implementing an algorithm. Now the algorithm is finished and initial tests tells me that is works with respect to the solution it produces. Unfortunately it seems that the code does not scale with the problem instances I give it.
I have revised the method and it seems impossible that its the theory that is bugged. It _should_ scale reasonably. Hence, my money is on my poor implementation of the algorithm.
Looking at the Debug-> Windows -> Locals (Visual Studio 2008), I see a lot of variables I thought was deleted long ago. Also the size of them seems excessive. So I am thinking I have a memory leak. Well, leak might be a strong word, since I think the real problem is that I thought vectors from the STL behaved in a certain way.
The code it self is rather long (2000 lines +) so I will try to simplify my question regarding the vectors behavior.
Code:
//A function definition before the main
InitializeVector(vector<int>* pNumber)
{
vector<int> temp;
//Do stuff with the vectors
}
VectorFun()
{
vector<int> NumberVector;
vector<int>* pNumberVector;
pNumberVector=& NumberVector;
InitializeVector(pNumberVector);
}
main()
{
//Somewhere in the main function
VectorFun();
My question is now, will the vector temp be completly deleted after InitializeVector is run? Also will the NumberVector and pointer be deleted after the VectorFun?
Basically, will they remain ghosts in my memory or are they dead and gone?
Thank you in advance for time spendt on this *I think* easy question.
EDIT: Fixed the assignment of the pointer as stated in #2