Code archives/Miscellaneous/Memory Monitor

This code has been declared by its author to be Public Domain code.

Download source code

Memory Monitor by Mark Tiffany2007
Include the code below into your source (suggest you wrap the include with ?debug) to get a small GUI window that will show current memory usage, without having to amend any of your code. Very handy for tracking down memory leaks!
Global memcheckwin:Tgadget
Global memchecktimer:TTimer

memchecktimer=CreateTimer(10)
AddHook EmitEventHook , _memcheck_hook,memchecktimer

Function ShowMem()
	Local m:Long
	If memcheckwin = Null Then
		memcheckwin = CreateWindow("Memory Usage" , GadgetWidth(Desktop() ) - 250 , 0 , 250 , 30 , Null , WINDOW_TITLEBAR)
	End If
	GCCollect() 
	m = GCMemAlloced() 
	SetGadgetText memcheckwin , "Memory Usage: " + m
End Function

Function _memcheck_hook:Object(id:Int , data:Object , context:Object) 
	Local e:TEvent
	e=TEvent(data)
	If e.source = memchecktimer And e.id=EVENT_TIMERTICK Then
		ShowMem() 
		Return Null
	Else
		Return data
	End If
End Function

Comments

None.

Code Archives Forum