Go Back   Rhinocerus > Newsgroup > Newsgroup comp.lang.* 1 > Newsgroup comp.lang.fortran

Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old 02-07-2012, 11:34 AM
Sebastien Bardeau
Guest
 
Posts: n/a
Default Detecting memory leaks with gfortran?

Hello,

I am wondering if gfortran provides an option to report memory leaks at
runtime, like g95 did (implicitely) in the past:

program test
real(kind=4), pointer :: a(
!
allocate(a(1000))
a => null()
allocate(a(1000))
deallocate(a)
end program test

g95 output at the end of execution:

Remaining memory: 4000 bytes at 000000000bf56338 allocated at line 4 of
test.f90

I found this thread where a patch is proposed, but can not find it in
the gfortran (4.7.0) options:
http://gcc.gnu.org/ml/fortran/2008-11/msg00380.html

Any idea?

Thanks.
Reply With Quote
Alt Today
Advertising
 
and become member of Rhinocerus
Standard Sponsored Links

  #2 (permalink)  
Old 02-07-2012, 12:01 PM
Tobias Burnus
Guest
 
Posts: n/a
Default Re: Detecting memory leaks with gfortran?

On 02/07/2012 01:34 PM, Sebastien Bardeau wrote:
> I am wondering if gfortran provides an option to report memory leaks at
> runtime, like g95 did (implicitely) in the past:
>
> g95 output at the end of execution:
>
> Remaining memory: 4000 bytes at 000000000bf56338 allocated at line 4 of
> test.f90
>
> I found this thread where a patch is proposed, but can not find it in
> the gfortran (4.7.0) options


I think there were some issues with the patch. It is still planed to
support it eventually, but it has not yet been implemented.

However, you can use valgrind to find memory leaks, available at
http://valgrind.org/ (It should work on all common platforms but
Windows.) As it is frequently used during development, there shouldn't
be any valgrind warnings or memory leaks due to the compiler itself.
(Except for some known issues with polymorphic variables.)

Tobias
Reply With Quote
  #3 (permalink)  
Old 02-08-2012, 09:29 AM
Sebastien Bardeau
Guest
 
Posts: n/a
Default Re: Detecting memory leaks with gfortran?

Le 02/07/2012 02:01 PM, Tobias Burnus a écrit :
> On 02/07/2012 01:34 PM, Sebastien Bardeau wrote:
>> I am wondering if gfortran provides an option to report memory leaks at
>> runtime, like g95 did (implicitely) in the past:
>>
>> g95 output at the end of execution:
>>
>> Remaining memory: 4000 bytes at 000000000bf56338 allocated at line 4 of
>> test.f90
>>
>> I found this thread where a patch is proposed, but can not find it in
>> the gfortran (4.7.0) options

>
> I think there were some issues with the patch. It is still planed to
> support it eventually, but it has not yet been implemented.
>
> However, you can use valgrind to find memory leaks, available at
> http://valgrind.org/ (It should work on all common platforms but
> Windows.) As it is frequently used during development, there shouldn't
> be any valgrind warnings or memory leaks due to the compiler itself.
> (Except for some known issues with polymorphic variables.)


Indeed, Valgrind... A quick run shows me that it is probably a bit too
much for me. In particular it tracks the memory leaks in the system or
external libraries my program in linked against. Ok it can probably be
tuned, but this will take time to learn.

I would have prefered a simple way to detect leaks in the libraries I
compiled with the check enabled. As g95 did... So if you wonder if
gfortran should provide or not such an option, I vote yes!

Thanks for your help.
Reply With Quote
  #4 (permalink)  
Old 02-08-2012, 10:39 AM
Alberto Luaces
Guest
 
Posts: n/a
Default Re: Detecting memory leaks with gfortran?

Sebastien Bardeau writes:

> Le 02/07/2012 02:01 PM, Tobias Burnus a écrit :
>> On 02/07/2012 01:34 PM, Sebastien Bardeau wrote:
>>> I am wondering if gfortran provides an option to report memory leaks at
>>> runtime, like g95 did (implicitely) in the past:
>>>
>>> g95 output at the end of execution:
>>>
>>> Remaining memory: 4000 bytes at 000000000bf56338 allocated at line 4 of
>>> test.f90
>>>
>>> I found this thread where a patch is proposed, but can not find it in
>>> the gfortran (4.7.0) options

>>
>> I think there were some issues with the patch. It is still planed to
>> support it eventually, but it has not yet been implemented.
>>
>> However, you can use valgrind to find memory leaks, available at
>> http://valgrind.org/ (It should work on all common platforms but
>> Windows.) As it is frequently used during development, there shouldn't
>> be any valgrind warnings or memory leaks due to the compiler itself.
>> (Except for some known issues with polymorphic variables.)

>
> Indeed, Valgrind... A quick run shows me that it is probably a bit too
> much for me. In particular it tracks the memory leaks in the system or
> external libraries my program in linked against. Ok it can probably be
> tuned, but this will take time to learn.


What about ignoring all notifications not concerning your code directly?
With --track-origins=yes you just see where the allocations were made.

--
Alberto
Reply With Quote
 
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




All times are GMT. The time now is 05:13 AM.


Copyright ©2009

LinkBacks Enabled by vBSEO 3.3.0 RC2 © 2009, Crawlability, Inc.