G
Gus Gassmann
I have been working with C++ for about four years now, mostly self-
taught, and I get along reasonably well. However, last week I detected
a memory leak in some code, and trying to locate it I realized that I
do not know enough about destructors. I have created a number of use
cases. How can I make sure in each case that the memory gets destroyed
properly?
1. int *x[10];
2. int *y = new int[10];
3. Object *obj = new Object();
4. Object **obj = new Object[n];
for (int i=0; i<n; i++) obj = new Object();
5. Object *obj = new Object();
obj->intArray = new int[10];
6. Object **obj = new Object[n];
for (int i=0; i<n; i++) {
obj = new Object();
obj->intArray = new int[10];
}
In advance, thanks very much.
taught, and I get along reasonably well. However, last week I detected
a memory leak in some code, and trying to locate it I realized that I
do not know enough about destructors. I have created a number of use
cases. How can I make sure in each case that the memory gets destroyed
properly?
1. int *x[10];
2. int *y = new int[10];
3. Object *obj = new Object();
4. Object **obj = new Object[n];
for (int i=0; i<n; i++) obj = new Object();
5. Object *obj = new Object();
obj->intArray = new int[10];
6. Object **obj = new Object[n];
for (int i=0; i<n; i++) {
obj = new Object();
obj->intArray = new int[10];
}
In advance, thanks very much.