Topic: Possible Memory Leak

I reason to think that I may have recently introduced a memory leak in my code. Through all my various versions during decades of development of my code, I have always noted that the memory usage was rock solid stable. I have researched a bit on memory leaks and have seen some of the potential causes, like using pointers and allocate statements. However, I do not use those constructs in my code, I am a relative simpleton coder and do nothing fancy to my mind. For example, I just recently learned how to do inline formatting of write statements (D'oh!).

It looks like code I produced earlier this year is memory stable but the latest code seems to use an ever increasing amount of memory. The one notable new thing (other than the aforementioned inline formatting) for the code was the use of one integer*8 variable and its use in a common block. Common blocks are new to me and my code and I think I am doing this correctly but I suspect there can be the potential for alignment issues. I noted that I had the large integer declared after the common declaration, like so (Note MaxIt is a regular integer):
.
.
common / Iteration / Iter8,MaxIt
.
.
integer*8 Iter8

Not sure why I did it like that but could that cause a problem? This morning I changed the code everywhere the common block appears it to be more like:
.
.
integer*8 Iter8
common / Iteration / Iter8,MaxIt
.
.

I have rebuilt the code as above am testing the memory usage. If you can think of anything else that might cause memory leaks, please educate me. Thanks.

Rod

2 (edited by ecanot 2015-10-18 19:18:21)

Re: Possible Memory Leak

Alignment issues cannot give a memory leak, but only less performance (a little bit, however). By nature, only dynamic allocation leads to memory leak (or, of course, compiler bugs) !

A useful and very powerful tool to discover and kill memory leaks is 'valgrind'. I am using it under linux but I don't know if it works under windows...

Re: Possible Memory Leak

Valgrind is Linux only.

A similar and just as powerful tool, which works under windows (and Linux and Mac), is Drmemory.

http://www.drmemory.org/

You compile with debugging information. Run your code using drmemory (drmemory -- mycode) then wait for a report of your memory leaks and references to any undefined variables. Highly recommended.

--
David