(FBMLD) FreeBASIC Memory Leak Detector

Post your FreeBASIC tips and tricks here. Please don’t post your code without including an explanation.
Nexinarus
Posts: 146
Joined: May 28, 2005 6:08
Location: Everywhere
Contact:

Postby Nexinarus » Dec 26, 2008 3:46

I second relsoft, any chances this can support new or delete, or some alternative?
yetifoot
Posts: 1710
Joined: Sep 11, 2005 7:08
Location: England
Contact:

Postby yetifoot » Jan 05, 2009 13:52

It's been a long time, but from memory...

NEW/DELETE can't be simply added to fbmld, as they are operators, not functions, so can't be done with #define or #macro

I can't remember if global new/delete overloading got added to the operator overloading... If it was added at all, I think it was just per TYPE, so fbmld can't know about all types.

I completed the work I mentioned in the earlier post, of adding mld into the compiler itself, as this way it can trap new/delete with no issues.

However it was not added in when I submitted the patch, I can't remember the exact reasons now, but I think v1c felt it may conflict with something in the future, or was just not appropriate to be built in, he would know more about that than me so I let it drop.

Now, I just use the program Valgrind (especially the memcheck part) to do this kind of analysis, I find it does the leak detection, and more, it can find out of bounds reads/writes aswell, it's a great tool. The only problem is that it is not available for anything other than Linux, and no-one has ever been able to give me a comparative free tool for windows that I can recommend to people.
pr0gger
Posts: 47
Joined: Oct 27, 2006 23:10

Postby pr0gger » Jan 07, 2009 21:45

This is long overdue, but:

Thanks for this, DrV. Helped me track down some huge leaks.
vdecampo
Posts: 2982
Joined: Aug 07, 2007 23:20
Location: Maryland, USA
Contact:

Postby vdecampo » Feb 10, 2009 20:45

I am having trouble getting the FBMLD to work. The problem is not so much with FBMLD but with the way I have declared memory allocation functions. In order to easily change between internal FB memory allocation and WinAPI routines, I created these #Defines...

Code: Select all

'#Define MemAlloc(x)     GlobalAlloc(0,x)
'#Define MemFree         GlobalFree
#Define MemAlloc(x)     Allocate(x)
#Define MemFree         DeAllocate


But when I include FBMLD.bi, I get errors....

error 10: Expected '=', found 'this' in 'MemFree this.GetState'
error 4: Duplicated definition, DeAllocate in 'MemFree ThisPtr->Chan'


When I remove FBMLD.bi, everything compiles fine.

Please help. I hope there is a way I can use this.

-Vince
vdecampo
Posts: 2982
Joined: Aug 07, 2007 23:20
Location: Maryland, USA
Contact:

Postby vdecampo » Feb 10, 2009 20:50

OK I replaced my #Defines to call subroutines to encapsulate the memory calls.

Code: Select all

Function _MemAlloc(x As Integer) As Any Ptr
   Return Allocate(x)
End Function

Sub _MemFree(x As Any Ptr)
   DeAllocate x
End Sub


Now I just get 1 error message...
error 41: Variable not declared, DeAllocate in 'DeAllocate x'


Still stuck. :(

-Vince
vdecampo
Posts: 2982
Joined: Aug 07, 2007 23:20
Location: Maryland, USA
Contact:

Postby vdecampo » Feb 10, 2009 20:51

OK. I put the x in parens and now it compiles! Thanks for the help! :/

-Vince
counting_pine
Site Admin
Posts: 6219
Joined: Jul 05, 2005 17:32
Location: Manchester, Lancs

Postby counting_pine » Feb 11, 2009 7:21

Yeah, the substituted allocate/deallocate are macros, so the args need to be in parentheses.

Note that the wrapper subs aren't necessary now - in fact they will only serve to mask the locations in code where you allocated the memory, since allocate will only get called directly from your wrapper sub ;)

Return to “Tips and Tricks”

Who is online

Users browsing this forum: No registered users and 4 guests