CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   OpenFOAM Programming & Development (https://www.cfd-online.com/Forums/openfoam-programming-development/)
-   -   freeing objects in OpenFOAM (https://www.cfd-online.com/Forums/openfoam-programming-development/228857-freeing-objects-openfoam.html)

Gerry Kan July 17, 2020 06:05

freeing objects in OpenFOAM
 
Howdy Foamers:

In a function I declared an instance of DynamicList. Textbook C++ told me that I should be deallocating this in the class destructor or, when it is declared in a function, I should delete it once it is not used anymore.

However, I don't see anything to that effect. The question is, do I have to do this, or these are being done "ad hoc" somewhere in the OpenFOAM code?

Thanks in advance, Ed.

Zeppo July 19, 2020 14:10

Heap memory is deallocated in the destructor of List class which DinamicList class is derived from. Take a look:
template<class T>
Code:

Foam::List<T>::~List()
 {
    if (this->v_)
    {
        delete[] this->v_;
    }
 }


Gerry Kan July 20, 2020 02:41

Dear Sergei:

It looks like I still have to learn how to traverse the OpenFOAM object inheritance tree. Thank you very much for pointing that out and this put my mind at ease with your response.

Sincerely yours, Gerry.


All times are GMT -4. The time now is 08:23.