// Create List
CanvasText.Initialize(Activity)
For i = 0 To ValuesItems.Size - 1
// if don't run the function the memory leak is already present
Label1.Text = TrimWidth(CanvasText, Label1.Text, Label1.Typeface, Label1.TextSize, LabelWidth)
Next
Sub TrimWidth(CanvasText As Canvas, Text As String, Style As Typeface, Size As Int, MaxWidth As Int) As String
Dim Width As Int
If Style.IsInitialized = False Then
Style = Typeface.DEFAULT
End If
Width = CanvasText.MeasureStringWidth(Text, Style, Size)
If Width >= MaxWidth Then
Do Until Width < MaxWidth
Text = Text.SubString2(0, Text.Length - 1)
Width = CanvasText.MeasureStringWidth(Text, Style, Size)
Loop
Text = Text.SubString2(0, Text.Length - 3) & "..."
Return Text
Else
Return Text
End If
End Sub