Memory leak In my code
Hey everyone, I written a pretty heavy code, which runs. The problem is that it accumulate memory usage with time and I have no clue to where it can be. Is there a debug option or something that I can use to check if something is getting constructed and not destructed.
I'm using a lot of(almost exculsively) autoPtr = new ... to store datas, maybe it is the origin. They are meant to be dynamically modified (ownership transferred with = or redefined completely with an other = new... ) Basically I have a mesh of 61777 cells, with all tests passing (except 4 faces that are severy non-orthogonal). And at the beggining, I use something like 0.72Gb of RAM. But after 40 000time step I'm at like 8Gb. Thank you a lot for your help Fabien |
You can use tools like valgrind to detect memory leaks.
|
Thank you for your answer. That's what I've done (with debugging mode compilation)
The problem is that I do not understand the results to be honnest. I tried both with the memcheck tool and massif tool. In my code it seems that stuffs are allocated, and never removed. I have a lot of trouble finding the culprit(s). I would use massif for that kind of problem, but I have a nice graph but cannot identify when in my code this happens. |
Dear Fabien:
Just a very naive question ... did you also call the delete function for each of the dynamically allocated memory for your variables once you don't need them anymore? Gerry. |
I have used the tool some time back. I think you should find some document online to explain output. Also if you are using autoPtr then the are meant for memory handling and call delete in destructor.
|
Yes, this it the main reason why I use autoPtr.
Well, I think I found "the" (probably "a") problem: I need to frequently use interpolation on a tmp<volScalarField>. I do It with Code:
autoPtr<interpolation<Type>> interp Code:
template<class Type> Code:
Code:
Constructing IOobject called volPointInterpolate(potField) of type IOobject I think this is were the memory fills! Each time this intep is called, It seems that I add and never delete the member psip_ (a pointField) of interpolationCellPoint.H I tried to add Code:
interp.clear(); Any advice on this?? |
Fabien:
You are right with the autoPtr. I am still stuck in old school, preferring to taking care of memory allocation by myself! Code:
autoPtr<interpolation<Type>> interp Code:
volPointInterpolation::New(psi.mesh()).interpolate Would it be possible to create the tmp<volScalarField> in question before hand, and use it as argument and then delete() them by yourself. Gerry. |
Well, I didn't found a clean solution. that really erases the members of interp.
I had confirmation when I tried to print what is contained in the objectRegistry, that a lot of volScalarFields accumulate inside in (everyone named volPointInterpolate(blabla)) where blabla reprensents the operation done to compute "potField". The (not clean workaround) is to use the same name, because "cache" is used (see bove). That way, the volPointInterpolate is cleared when renewed... If someone wants, here is the small script to execute on your log to get everything written in the object registries. Code:
CheckInAndOut.sh: |
Quote:
Well, this is what I tought, to be honest, I have tought about this method. Creating a "localCellPoint" method that does not store it into "cache". Or takes as an entry the volPointInterpolate field. But the problem of this is that in that case I could not replace "cellPoint" by another preexisting method of interpolation. As I said in my previous post (I didn't see your answer at that time), I ve managed to find a way to avoid the problem, even if I know it is not really clean nor elegant. |
All times are GMT -4. The time now is 00:33. |