finding Memory Leak lazarus / 12-Debugger ---------------------------------------------------------------------- x2nie · 2016-01-07 12:06 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. ---------------------------------------------------------------------- x2nie · 2016-01-07 12:23 maybe it just fine in lazarus (no memory leak). ?   maybe the problem is {$ifndef fpc} Usually lazarus report any problem, but this day lazarus didn't. maybe it just good. 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 ---------------------------------------------------------------------- wp · 2016-01-07 12:27 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 · 2016-01-07 12:36 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? ---------------------------------------------------------------------- bylaardt · 2016-01-07 12:46 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 · 2016-01-07 12:47 Quote from: x2nie on January 07, 2016, 01:36:26 pmWait, is there a way to see the generated output of heaptrc somewhere? yes: http://wiki.freepascal.org/leakview#Enabling_heaptrc_in_Lazarus ---------------------------------------------------------------------- x2nie · 2016-01-07 13:06 Woooouww........!  Thanks you guys, ah- finally,,,,,, 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)? ---------------------------------------------------------------------- x2nie · 2016-01-07 13:20 Quote from: bylaardt on January 07, 2016, 01:46:46 pmAre 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. ---------------------------------------------------------------------- taazz · 2016-01-07 14:52 Quote from: x2nie on January 07, 2016, 02:06:41 pmOne 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