Page 4 of 4
Re: NoLeak - include to help you find memory leaks (1.4)
Posted: Fri Sep 06, 2013 10:50 am
by Fred
ClearStructure() is only needed if you call InitializeStructure() somewhen (After AllocateMemory() for example). Beside that, all is automatically managed by PB.
Re: NoLeak - include to help you find memory leaks (1.3)
Posted: Fri Sep 06, 2013 10:56 am
by luis
sec wrote:
I get macro error:
Thanks. I did left an old param for catchimage() not present anymore. Hope it's ok now.
And yes, noleak catches only one class of macroscopic errors basically... (mismatched allocations/deallocations through allocatememory/freememory). It's a very limited tool.
It can help in some cases, but cannot do what you can do manually, and I feel trying to add more "intelligence" to it would cause more false reports than not.
For GDI leakages look at the GDIView tool mentioned in my first post (it can't tell you were they are in your code but it can help to verify their presence and the kind of objects leaking).
Re: NoLeak - include to help you find memory leaks (1.4)
Posted: Mon Sep 09, 2013 2:02 am
by yrreti
Thank you much luis for sharing this program, and infratec for your addin part.
I like this NoLeak detector, as it helps me correct mistakes that lead to leak errors in my programs.
But I like infratec's approach for more location detail. But for what it's worth, I also added the line
'text' to the problem causing line number for a quick reference with out having to go to the line to
see what's wrong. It is in the following code. Just add to luis's source as infratec says on page 2.
I posted it here in case anyone else wants to use it too.
Code: Select all
;{ DebugNoLeak()
Procedure DebugNoLeak()
Shared NoLeak_FONT(), NoLeak_ALLOC(), NoLeak_IMAGE()
Protected i,TheSource$,lp.i,TmpFile$,line_pos.i,thedat$
i = 0
If ListSize(NoLeak_FONT())
Debug ""
Debug "NoLeak Font:"
Debug ""
ForEach NoLeak_FONT()
i + 1
Debug "(" + Str(i) + ") " + "File: " + NoLeak_FONT()\Source$
line_pos=NoLeak_FONT()\iLine
TheSource$=NoLeak_FONT()\Source$
TmpFile$ = GetPathPart(TheSource$)+"tmp.txt"
While CopyFile(TheSource$, TmpFile$)=0:Wend
ReadFile(1,TmpFile$)
lp=0
While Eof(1) = 0
thedat$=ReadString(1)
lp=lp+1
If lp=line_pos
Debug "(" + Str(i) + ") " + "Line: " + Str(line_pos)+" "+thedat$
Break
EndIf
Wend
CloseFile(1)
DeleteFile(TmpFile$)
Debug "(" + Str(i) + ") " + "ID: " + Str(NoLeak_FONT()\iFontNum)
Debug "(" + Str(i) + ") " + "Name: " + NoLeak_FONT()\Filename$
Debug "(" + Str(i) + ") " + "Size: " + Str(NoLeak_FONT()\iYsize)
Debug ""
Next
Debug "----------------------------"
EndIf
If ListSize(NoLeak_ALLOC())
Debug ""
Debug "NoLeak Alloc:"
Debug ""
ForEach NoLeak_ALLOC()
i + 1
Debug "(" + Str(i) + ") " + "File: " + NoLeak_ALLOC()\Source$
line_pos=NoLeak_ALLOC()\iLine
TheSource$=NoLeak_ALLOC()\Source$
TmpFile$ = GetPathPart(TheSource$)+"tmp.txt"
While CopyFile(TheSource$, TmpFile$)=0:Wend
ReadFile(1,TmpFile$)
lp=0
While Eof(1) = 0
thedat$=ReadString(1)
lp=lp+1
If lp=line_pos
Debug "(" + Str(i) + ") " + "Line: " + Str(line_pos)+" "+thedat$
Break
EndIf
Wend
CloseFile(1)
DeleteFile(TmpFile$)
Debug "(" + Str(i) + ") " + "Address: " + Str(NoLeak_ALLOC()\iAddress)
Debug "(" + Str(i) + ") " + "Size: " + Str(NoLeak_ALLOC()\iBytes)
Debug ""
Next
Debug "----------------------------"
EndIf
If ListSize(NoLeak_IMAGE())
Debug ""
Debug "NoLeak Image:"
Debug ""
ForEach NoLeak_IMAGE()
i + 1
Debug "(" + Str(i) + ") " + "File: " + NoLeak_IMAGE()\Source$
line_pos=NoLeak_IMAGE()\iLine
TheSource$=NoLeak_IMAGE()\Source$
TmpFile$ = GetPathPart(TheSource$)+"tmp.txt"
While CopyFile(TheSource$, TmpFile$)=0:Wend
ReadFile(1,TmpFile$)
lp=0
While Eof(1) = 0
thedat$=ReadString(1)
lp=lp+1
If lp=line_pos
Debug "(" + Str(i) + ") " + "Line: " + Str(line_pos)+" "+thedat$
Break
EndIf
Wend
CloseFile(1)
DeleteFile(TmpFile$)
Debug "(" + Str(i) + ") " + "ID: " + Str(NoLeak_IMAGE()\iImageNum)
Debug "(" + Str(i) + ") " + "Width: " + Str(NoLeak_IMAGE()\iWidth)
Debug "(" + Str(i) + ") " + "Height: " + Str(NoLeak_IMAGE()\iHeight)
Debug "(" + Str(i) + ") " + "Depth: " + Str(NoLeak_IMAGE()\iDepth)
Debug ""
Next
Debug "----------------------------"
EndIf
If i > 0
Debug "NoLeak found " + Str(i) + " leaks!"
Else
Debug "NoLeak found no leaks!"
EndIf
EndProcedure
;}
CompilerElse
Macro DebugNoLeak()
EndMacro
yrreti
Re: NoLeak - include to help you find memory leaks (PB5.20)
Posted: Thu Sep 19, 2013 6:51 pm
by Danilo
@luis:
If you change the line
Code: Select all
Macro CreateImage (iImageNum, iWidth, iHeight, iDepth = 24, iBackColor = #Black)
to:
Code: Select all
Macro CreateImage (iImageNum, iWidth, iHeight, iDepth = 24, iBackColor = RGB(0,0,0))
it works also on Mac OS X (and probably GNU/Linux).
Re: NoLeak - include to help you find memory leaks (PB5.20)
Posted: Thu Sep 19, 2013 7:37 pm
by luis
@Danilo
I changed it, thanks.
Re: NoLeak - include to help you find memory leaks (PB5.20)
Posted: Wed Jun 01, 2016 12:34 am
by Lunasole
Thanks, nice memory-related addition to Purifier and really cool stuff, -1 way to be a fool [million remains]
