Recent

Author Topic: finding Memory Leak  (Read 7697 times)

x2nie

  • Hero Member
  • *****
  • Posts: 515
  • Impossible=I don't know the way
    • impossible is nothing - www.x2nie.com
finding Memory Leak
« on: January 07, 2016, 01:06:46 pm »
Today I am creating (porting) components from Toolbar97.
In the beginning, I create the skeleton by my self.
But for the rest, I just copy + paste the codes.


In every middle things, I tried the code using delphi. Delphi crashes several time (maybe out of memory).


Now the problem is : the package + components + demo app running very well with Lazarus.
But Delphi always reports : Exception EAccessViolation in module project1.exe at 0368E.
I suspect (most probably) there was something missed by me.
Well, the code is very messy now, it hard to remember what procedure wasn't properly proted.
Using diff doesn't help, then.

Question 1: How to find/activate memory leak in Lazarus? my delphi doesn't report the file and line number.
2: Can it point to file & line number of the memory leak?
I don't know anything about Valgrind. I know someone use it to find memory leak in C.


I am using Windows XP Lazarus trunk.


Thanks for attention/answer.
When you were logged in, you can see attachments.
Lazarus Github @ UbuntuCinnamon-v22.04.1 + LinuxMintDebianEdition5

x2nie

  • Hero Member
  • *****
  • Posts: 515
  • Impossible=I don't know the way
    • impossible is nothing - www.x2nie.com
Re: finding Memory Leak
« Reply #1 on: January 07, 2016, 01:23:57 pm »
maybe it just fine in lazarus (no memory leak). ? :D  maybe the problem is {$ifndef fpc}


Usually lazarus report any problem, but this day lazarus didn't. maybe it just good. O:-)





if you somebody have time and can try, please tell me if there is something wrong.


code: svn: https://github.com/x2nie/flying-toolbar/trunk/AquaToolbar
When you were logged in, you can see attachments.
Lazarus Github @ UbuntuCinnamon-v22.04.1 + LinuxMintDebianEdition5

wp

  • Hero Member
  • *****
  • Posts: 13216
Re: finding Memory Leak
« Reply #2 on: January 07, 2016, 01:27:22 pm »
To check for memory leaks just check the box "Use heaptrc unit" in "Project inspector" / "Compiler options" / "Debugging" / "Other debugging info", or add "-gh" to the compiler options.

x2nie

  • Hero Member
  • *****
  • Posts: 515
  • Impossible=I don't know the way
    • impossible is nothing - www.x2nie.com
Re: finding Memory Leak
« Reply #3 on: January 07, 2016, 01:36:26 pm »
oh!
Okay, I just checkmarked the "Use heaptrc unit". I run again. play play play, close the mainform,
then No error shown...
....and back to the IDE editor.


Wait, is there a way to see the generated output of heaptrc somewhere?

When you were logged in, you can see attachments.
Lazarus Github @ UbuntuCinnamon-v22.04.1 + LinuxMintDebianEdition5

bylaardt

  • Sr. Member
  • ****
  • Posts: 310
Re: finding Memory Leak
« Reply #4 on: January 07, 2016, 01:46:46 pm »
Are you sure is a memory leak?
this error is certain by a unassigned pointer, often overwritten pointer, ex:

form1.font:=form2.font;
when you destroy form1 In delphi, form2.font was destroyed too.
when you destroy form2, form2.font isn't there, then "EAccessViolation" error.

FPC no report this error because form1 haven't destroyed form2.font because depends on form1.insertcompoent to destroy anothers sub-components (or parent property assign)

hnb

  • Sr. Member
  • ****
  • Posts: 270
Re: finding Memory Leak
« Reply #5 on: January 07, 2016, 01:47:33 pm »
Checkout NewPascal initiative and donate beer - ready to use tuned FPC compiler + Lazarus for mORMot project

best regards,
Maciej Izak

x2nie

  • Hero Member
  • *****
  • Posts: 515
  • Impossible=I don't know the way
    • impossible is nothing - www.x2nie.com
Re: finding Memory Leak
« Reply #6 on: January 07, 2016, 02:06:41 pm »
Woooouww........!  :o


Thanks you guys, ah- finally,,,,,, ;D
for the first time, I see a small window/dialog "0 unfree memory blocks: 0".
It said "everything okay" right?


One more question:
How to activate the menuitem "View / Leak and Trace" in lazarus compiled from source (trunk)?

When you were logged in, you can see attachments.
Lazarus Github @ UbuntuCinnamon-v22.04.1 + LinuxMintDebianEdition5

x2nie

  • Hero Member
  • *****
  • Posts: 515
  • Impossible=I don't know the way
    • impossible is nothing - www.x2nie.com
Re: finding Memory Leak
« Reply #7 on: January 07, 2016, 02:20:49 pm »
Are you sure is a memory leak?
this error is certain by a unassigned pointer, often overwritten pointer, ex:

form1.font:=form2.font;
when you destroy form1 In delphi, form2.font was destroyed too.
when you destroy form2, form2.font isn't there, then "EAccessViolation" error.

FPC no report this error because form1 haven't destroyed form2.font because depends on form1.insertcompoent to destroy anothers sub-components (or parent property assign)
I never think about it in before. @bylaardt thanks you for insight explanation.
Delphi is my secondary compiler, since I still work using it together with several collages.
But as far as lazarus told it fine, I am fine.  8)
When you were logged in, you can see attachments.
Lazarus Github @ UbuntuCinnamon-v22.04.1 + LinuxMintDebianEdition5

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: finding Memory Leak
« Reply #8 on: January 07, 2016, 03:52:48 pm »
One more question:
How to activate the menuitem "View / Leak and Trace" in lazarus compiled from source (trunk)?
You have to instruct the heaptrc unit to not show the dialog but save the results in a file and then click on the view\leaks and traces.
http://wiki.lazarus.freepascal.org/leakview
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

 

TinyPortal © 2005-2018