- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello,
I am using Intel Fortran Compiler Integration for Microsoft Visual Studio 2005, Version 9.1.3192.2005. I am working on the code used for simulation developed by several programmers. The problem I have experienced is that during the execution of the code the virtual memory used keeps increasing. I have checked output units of the code, but I couldn't see anything suspicious. My idea is that there are POINTERS or ARRAYS being continuosly allocated throughout the code execution but there are not deallocated. Is there any way how to find out which variable in the code is resposible for this?
I am using Intel Fortran Compiler Integration for Microsoft Visual Studio 2005, Version 9.1.3192.2005. I am working on the code used for simulation developed by several programmers. The problem I have experienced is that during the execution of the code the virtual memory used keeps increasing. I have checked output units of the code, but I couldn't see anything suspicious. My idea is that there are POINTERS or ARRAYS being continuosly allocated throughout the code execution but there are not deallocated. Is there any way how to find out which variable in the code is resposible for this?
Link Copied
5 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The size of the Virtual Memory footprint is not (necessarily) an indication of a memory leak. The reason being is that depending on the heap code used by malloc allocations may tend to come from previously unused virtual memory addresses as opposed to recently returned memory. This allocation charactistic came inseveral years back to reduce allocation time (essentially eliminate search for best fit) and as an attempt to correct for bad programming whereby a buffer is use after it was returned.
Look in your C/C++ run time library for heap functions to obtain the information of interest. Check the example of _heapwalk, remove the printf(s) andsum up the sizes ofthe used entries. You may also want to sum up the sizes of the unused entries as well. The total of the two (plus some size for the portion of the program and stack obtained prior to establishing the heap) should equal the virtual memory size. If the USED portion grows then you may have a memory leak. If the USED portion establishes a fixed range of values but the FREE portion grows then the heap allocator is creaping along the virtual address space.
Also, depending on how your application allocates and returns memory, the pattern may be predisposed to creaping along the virtual memory address. Look in the MSDN under Low-fragmentation Heap.
An alternative approach is for you to roll your own object recycler.
Jim Dempsey
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Allocatable arrays will be automatically deallocated when they go out of scope.
However allocatable pointers can be a source of memory leaks. You need to search your code for "allocatable" and where it is associated with "pointer"then you will need to check each pointer through the code to see if and when it should be deallocated.
In the help see the "Static Verification Overview" which can help to diagnose these kinds of problems.
Les
However allocatable pointers can be a source of memory leaks. You need to search your code for "allocatable" and where it is associated with "pointer"then you will need to check each pointer through the code to see if and when it should be deallocated.
In the help see the "Static Verification Overview" which can help to diagnose these kinds of problems.
Les
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Quoting - Les Neilson
You need to search your code for "allocatable" and where it is associated with "pointer"then you will need to check each pointer through the code to see if and when it should be deallocated.
Might have been a typo, but I think that should be a search for ALLOCATE statements that work on variables with the POINTER attribute. I don't think a variable is allowed to have both the POINTER and ALLOCATABLE attributes.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Quoting - IanH
Might have been a typo, but I think that should be a search for ALLOCATE statements that work on variables with the POINTER attribute. I don't think a variable is allowed to have both the POINTER and ALLOCATABLE attributes.
Sorry, I had a bad day yesterday :-(
Yes it was unclear. I meant search for pointer and matchingallocatableTARGET variables.
Les
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Quoting - Les Neilson
Allocatable arrays will be automatically deallocated when they go out of scope.
However allocatable pointers can be a source of memory leaks. You need to search your code for "allocatable" and where it is associated with "pointer"then you will need to check each pointer through the code to see if and when it should be deallocated.
In the help see the "Static Verification Overview" which can help to diagnose these kinds of problems.
Les
However allocatable pointers can be a source of memory leaks. You need to search your code for "allocatable" and where it is associated with "pointer"then you will need to check each pointer through the code to see if and when it should be deallocated.
In the help see the "Static Verification Overview" which can help to diagnose these kinds of problems.
Les
When an allocatable array is deallocated, the memory is not returned to the OS. When allocating a new array, the space freed by the last deallocated array can be reused only if there is sufficient available space.
Exemple :
ALLOCATE (A(100))
ALLOCATE (B(10))
DEALLOCATE (A)
ALLOCATE (C(110))
In this exemple, C cannot be allocated in the space freed by the deallocation of A because B is still allocated thus the size of memory owned by the program will be 220 although it uses only 120.

Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page