-
memory leakage?
i have a question regarding memory leakage.
i have a attribute defined in the class like this:
MyClass* myObject;
function1 is invoked when the application starts, and allocates memory for myObject:
myObject=new MyClass(1);
function2 is latter ran, and does the following:
myObject=new MyClass(2);
does this lead to memory leakage? do i have to explicitly delete myObject first and then allocate memory for myObject once again? or can i do as i have done? (it is important for me that the object keeps the original name!).
thank you :)
-
>does this lead to memory leakage?
Sure does.
>do i have to explicitly delete myObject
If you're re-assigning the only pointer you have to it, yes.
>or can i do as i have done?
Nothing stopping you (unless you run out of memory), but if people see your code they may make fun of you.