help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: memory leak


From: prinzinger
Subject: Re: memory leak
Date: Thu, 24 May 2007 09:16:30 +0200

Thank you John!

Yeah you figured it out, that in fact was my problem.
:-) Hoorraay! Now it works!

The reasons it worked with small matrices was not due to their size, as you 
correctly wondered,
but due to the fact that I loaded them right after saving them to a file.
When I removed the save operartions, it didn't work, just like the "huge" 
matrices I build from images.

But now, of course, that works as well! :)
Thanks!

Michael


-----Ursprüngliche Nachricht-----
Von: "John W. Eaton" <address@hidden>
Gesendet: 24.05.07 04:20:58
An: Michael Prinzinger <address@hidden>
CC: address@hidden
Betreff: memory leak


On 23-May-2007, Michael Prinzinger wrote:

| 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!");
| }

Do you have a handler for this exception?

| MArray2<Complex>* m_array = new MArray2<Complex>(this->row, this->column, 
*(new Complex(0.0, 0.0)));

*(new Complex(0.0, 0.0) is definitely a leak as there can be no code
to delete the memory you are allocating with new (you haven't saved
the pointer it returns).  Also, I suspect there is no need for you to
be allocating m_array with new either.

| fread(m_array, sizeof((*m_array)(0)), sizeof(m_array), eigenmatrix_file);

This is probably the real source of your problem.  Your m_array
variable is a pointer to a single object of class MArray2<Complex>,
not a pointer to an array of Complex values.  Also, sizeof (m_array)
is probably not doing what you think it is.

I think you want something more like

  MArray2<Complex> m_array = MArray2<Complex> (this->row, this->column);
  size_t n = this->row * this->column;
  fread (m_array.fortran_vec (), sizeof (Complex), n, eigenmatrix_file);

| This code runs fine with small matrices, and I have no problems
| whatsoever.

That's surprising.

jwe



_______________________________________________________________
SMS schreiben mit WEB.DE FreeMail - einfach, schnell und
kostenguenstig. Jetzt gleich testen! http://f.web.de/?mc=021192




reply via email to

[Prev in Thread] Current Thread [Next in Thread]