Platforms to show: All Mac Windows Linux Cross-Platform

/Main/Memory Leak Testing


Required plugins for this example: MBS MacOSX Plugin

You find this example project in your Plugins Download as a Xojo project file within the examples folder: /Main/Memory Leak Testing

This example is the version from Mon, 6th Nov 2022.

Project "Memory Leak Testing.xojo_binary_project"
Class App Inherits WebApplication
EventHandler Function HandleURL(Request As WebRequest, Response As WebResponse) As Boolean If Request.Path = "test" Then Response.Write "Hello World" Response.Status = 200 Return True End If End EventHandler
EventHandler Sub Opening(args() as String) StartMemoryStatisticsTimer End EventHandler
Protected Sub StartMemoryStatisticsTimer() // start timer to print memory stats Static t As MemoryStatisticsTimer t = New MemoryStatisticsTimer t.Period = 2000 t.Mode = timer.ModeMultiple // query something, so it initializes Dim RuntimeObjectIterator As Runtime.ObjectIterator = Runtime.IterateObjects End Sub
End Class
Class Session Inherits WebSession
Const ErrorDialogCancel = "Do Not Send"
Const ErrorDialogMessage = "This application has encountered an error and cannot continue."
Const ErrorDialogQuestion = "Please describe what you were doing right before the error occurred:"
Const ErrorDialogSubmit = "Send"
Const ErrorThankYou = "Thank You"
Const ErrorThankYouMessage = "Your feedback helps us make improvements."
Const NoJavascriptInstructions = "To turn Javascript on, please refer to your browser settings window."
Const NoJavascriptMessage = "Javascript must be enabled to access this page."
End Class
Class WebPage1 Inherits WebPage
End Class
Class MemoryStatisticsTimer Inherits Timer
EventHandler Sub Action() // this stats show in Terminal when app runs as Standalone or you may see in debugger in messages System.DebugLog Str(Runtime.ObjectCount)+" objects using "+Str(runtime.MemoryUsed / 1024, "0.0")+" KB" counter = counter + 1 If counter Mod 10 = 0 Then // show stats every 10 seconds DumpObjects End If End EventHandler
Private Sub DumpObjects() // find all objects Dim objects() As Variant Dim RuntimeObjectIterator As Runtime.ObjectIterator = Runtime.IterateObjects While RuntimeObjectIterator.MoveNext objects.append RuntimeObjectIterator.Current Wend // for macOS, iOS and Linux compact memory and print stats #If Not TargetWindows Dim m As New MemoryStatisticsMBS m.Compact System.DebugLog Str(m.bytesFree)+" free, "+Str(m.bytesTotal)+" total" // free bytes shows how much space is available to be reassigned for new objects without requesting new memory pages from OS #EndIf // make a table with statistics Dim counts As New Dictionary Dim tab As String = Chr(9) For Each o As Variant In objects Dim t As Introspection.TypeInfo = Introspection.GetType(o) Dim s As String If t = Nil Then // internal objects s = "internal" Elseif o.IsArray Then s = "array" Else s = t.name End If Dim key As String = Str(VarType(o))+tab+s counts.Value(key) = counts.Lookup(key, 0).IntegerValue + 1 Next // make lines and sort, then print Dim lines() As String For Each key As Variant In counts.keys lines.Append key.StringValue + tab + counts.value(key) Next lines.Sort For Each line As String In lines Print line Next End Sub
Property Private counter As Integer
End Class
Sign
End Sign
End Project

The items on this page are in the following plugins: MBS Main Plugin.


The biggest plugin in space...