i have finish a big application, but work fine only for few minuts, it crash for out of memory.
i have read many threads on forum but i don't resolve.
FIRST PROBLEM
with monitor utility i have indentify the first section and problem of memory leak
i have a list of strings and use a canvas object and MeasureStringWidth for truncate the long strings
when i change the orientation of phone i lost about 2 Mb with the only initialization of canvas object
what is the right method for destroy canvas object ?
i have read many threads on forum but i don't resolve.
FIRST PROBLEM
with monitor utility i have indentify the first section and problem of memory leak
i have a list of strings and use a canvas object and MeasureStringWidth for truncate the long strings
when i change the orientation of phone i lost about 2 Mb with the only initialization of canvas object
what is the right method for destroy canvas object ?
B4X:
// 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