Example: /Main/Memory Leak Testing

Online Documentation   -   Statistics   -   FAQ   -   Plugin Parts (All, Dependencies)   -   Class hierarchy

New in Version 22.2 22.3 22.4 22.5 23.0 23.1 23.2 23.3 23.4 23.5 24.0 24.1

The list of the   topics,   classes,   interfaces,   controls,   modules,   global methods by category,   global methods by name,   screenshots,   licenses   and   examples.

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 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
End Project

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


💬 Ask a question or report a problem