Memory leak preventive practices


Finding memory leaks can be a daunting task. A good rule of thumb is to make sure that every allocated array is properly deallocated. However, one call to a deallocate command can free multiple arrays. This means that the lines of allocates and deallocates don't match (more than 3300 allocates and less than 2400 deallocates only, when searching the entire solution in VStudio).
Furthermore, the -heap-arrays option seems to trigger memory leaks, that eventually make simulations run out of virtual memory. Finally, recent changes in the code seemed to generate some memory leaks.
Hence, this issue is created to
a) Solve any eventual memory leak in the code at this stage.
b) Enforce the "one allocate, one deallocate per line" practice.

file attachments


guillaume7 wrote Jun 6, 2011 at 5:37 PM

Here's the memory evolution with memory leak. Memory leaks, such as in this case, only occur when the -heap-arrays option is used.

wrote Feb 14, 2013 at 1:13 AM