Xavior2K3
asked on
Memory Question
Hi,
I'm writing some software and im a little worried about leaking memory. If i create an object or array, and then assign that variable to a new instance of that object, will the memory of that previous object be freed?
Eg.
double[][] varA = new double[][];
MyObject varB = new MyObject();
....
varA = new MyObject(); // Will the object previously stored be freed?
varB = getNewArray(); // Will the array previously stored be freed?
// getNewArray() returns a pointer to a double[][] array that was created in the function
Thanks,
Michael
I'm writing some software and im a little worried about leaking memory. If i create an object or array, and then assign that variable to a new instance of that object, will the memory of that previous object be freed?
Eg.
double[][] varA = new double[][];
MyObject varB = new MyObject();
....
varA = new MyObject(); // Will the object previously stored be freed?
varB = getNewArray(); // Will the array previously stored be freed?
// getNewArray() returns a pointer to a double[][] array that was created in the function
Thanks,
Michael
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Great, thanks for clearing that up for me guys!
Only allocates a reference - nothing else
If all this is happening inside a method deallocation will occur on return