[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
memory leak
From: |
Michael Prinzinger |
Subject: |
memory leak |
Date: |
Wed, 23 May 2007 18:05:51 +0200 |
Good Day!
I have a problem with Octave potentially causing memory leaks.
I use liboctave in a C++ project with matrices.
The problem occurs, when I try to read a matrix, which I have saved previously.
Please have a look on the following code:
FILE* eigenmatrix_file = fopen(filename, "w");
if(eigenmatrix_file == NULL)
{
throw fileException("Error! in EigenMatrix::save(): can't open file!");
}
MArray2<Complex>* m_array = new MArray2<Complex>(this->row, this->column, *(new
Complex(0.0, 0.0)));
fread(m_array, sizeof((*m_array)(0)), sizeof(m_array), eigenmatrix_file);
This code runs fine with small matrices, and I have no problems whatsoever.
However after I try it with "real" matrices coming from 80x80 images I want to
work with (80x80 = 6400 values per image, that means 6400 x 6400=40960000
values or the matrix),
I get a segmentation fault accessing "eigenmatrix_file" after I created
m_array.
Fidling with the above code, I noticed that even a simple call like
eigenmatrix_file;
or
(eigenmatrix_file == NULL);
causes a seg fault after the creation of m_array.
I tried decalring m_array at the very beginning, before I declare and
initialize File* eigenmatrix_file, but even in this case, calling the resulting
pointer with the statements above (so no dereferencing, just calling the
pointer!) causes again a seg fault.
If I outcomment
// MArray2<Complex>* m_array = new MArray2<Complex>(this->row, this->column,
*(new Complex(0.0, 0.0)));
I don't get this seg fault.
So I have come to the conclusion, that creating
a new MArray2<Complex>(this->row, this->column, *(new Complex(0.0, 0.0)));
where row and column are pretty large,
causes Octave to somehow destroy my C++ stack, at least my previously defined
variables get lost.
Note that in general Octave has no problem with large matrices in my programm.
If the file "filename" does not exist the corresponding matrix is computed and
saved without error, only after trying to load a matrix this large, this error
occurs.
I hope you can help, I really need to solve this one, to be able to hand in my
university project ;)
Thank You
Michael Prinzinger
_______________________________________________________________
SMS schreiben mit WEB.DE FreeMail - einfach, schnell und
kostenguenstig. Jetzt gleich testen! http://f.web.de/?mc=021192
- memory leak,
Michael Prinzinger <=