L
luke
Hi,
my program has a memory leak and I can't handle it.
Basically, there are two classes, class_a and class_b, and one
object of each class: class_a obj_a, and class_b obj_b.
One of the methods of class_a is basically
float* class_a::get_data(int n) {
float *to_return = new float[n];
.. //computing entries in to_return
return to_return;
}
and one of the methods of class_b is basically
void class_b::use_data() {
float* data;
data = pointer_to_class_a -> get_data(s) ;
.. //using data;
delete [] data;
}
where s and pointer_to_class_a are members of class_b, and the latter
points to obj_a.
The method use_data() is used many times in the program, and it's the
only place where get_data(int) is used. However, the size of the program
(reported by top in linux)
increases drastically in time (use_data is used many times a second).
What do I do wrong? (to be honest, there are some other uses of new in
the program, but I don't suppose they are significant).
Best,
Lukasz Grabowski
my program has a memory leak and I can't handle it.
Basically, there are two classes, class_a and class_b, and one
object of each class: class_a obj_a, and class_b obj_b.
One of the methods of class_a is basically
float* class_a::get_data(int n) {
float *to_return = new float[n];
.. //computing entries in to_return
return to_return;
}
and one of the methods of class_b is basically
void class_b::use_data() {
float* data;
data = pointer_to_class_a -> get_data(s) ;
.. //using data;
delete [] data;
}
where s and pointer_to_class_a are members of class_b, and the latter
points to obj_a.
The method use_data() is used many times in the program, and it's the
only place where get_data(int) is used. However, the size of the program
(reported by top in linux)
increases drastically in time (use_data is used many times a second).
What do I do wrong? (to be honest, there are some other uses of new in
the program, but I don't suppose they are significant).
Best,
Lukasz Grabowski