[Gambas-user] How to regain the used memory after clearing the array?
M. Cs.
mohareve at ...626...
Tue Feb 21 14:01:26 CET 2012
Hello!
I have this problem with arrays. I have a class Keress given with this:
' Gambas class file
Export
' Gambas module file
Create Static
Private nev As New String[]
Private ut As New String[]
Private nagy As New Float[]
Private mikor As New String[]
Private kotet As New String[]
Public SConn As New Connection
Public Sub Search(y As Integer, stext As String, detect As String,
direction As String) As Integer '########################### Do the
search for files/folders ##########################
Dim dis As Integer = 0
Dim n, m, i, j As Integer
Dim visszhang, subhang As Result
Dim dubl, indexer As String[]
Dim quert, point, mkb, xkl, fullsearch As String
Dim nyogd As TextLabel
Dim keep As PictureBox
SConn.Name = "GamCat"
SConn.Type = "sqlite"
SConn.Host = User.Home & "/.GamCat"
SConn.Open()
If FMain.holder.value = False Then
Trashing()
Endif
FMain.gV.Columns.Count = 5
Select Case y
Case 1
If FMain.only.Value = True Then
visszhang = SConn.Exec("SELECT * FROM CENTRAL WHERE Category=&1 AND
FName=&2 AND (FSubs='0' OR FSubs='3') ORDER BY " & detect & " " &
direction & ";", FMain.SelcatBox.Text, stext)
For Each visszhang
dis = Insert(visszhang!"FName", visszhang!"FPath",
Round(visszhang!"FSize" / 1048576, -2), visszhang!"FChanged",
visszhang!VName)
Next
FMain.gV.Rows.Count = dis
For i = 0 To dis - 1
FMain.gv_Data(i, 0)
FMain.gv_Data(i, 1)
FMain.gv_Data(i, 2)
FMain.gv_Data(i, 3)
FMain.gv_Data(i, 4)
Next
Else
visszhang = SConn.Exec("SELECT * FROM CENTRAL WHERE FName=&1 AND
(FSubs='0' OR FSubs='3') ORDER BY " & detect & " " & direction & ";",
stext)
For Each visszhang
dis = Insert(visszhang!"FName", visszhang!"FPath",
Round(visszhang!"FSize" / 1048576, -2), visszhang!"FChanged",
visszhang!VName)
Next
FMain.gV.Rows.Count = dis
For i = 0 To dis - 1
FMain.gv_Data(i, 0)
FMain.gv_Data(i, 1)
FMain.gv_Data(i, 2)
FMain.gv_Data(i, 3)
FMain.gv_Data(i, 4)
Next
Endif
Case 2 '!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
If FMain.only.Value = True Then
visszhang = SConn.Exec("SELECT * FROM CENTRAL WHERE Category=&1 AND
FName LIKE &2 AND (FSubs='0' OR FSubs='3') ORDER BY " & detect & " " &
direction & ";", FMain.SelcatBox.Text, "%" & stext & "%")
For Each visszhang
dis = Insert(visszhang!"FName", visszhang!"FPath",
Round(visszhang!"FSize" / 1048576, -2), visszhang!"FChanged",
visszhang!VName)
Next
FMain.gV.Rows.Count = dis
For i = 0 To dis - 1
FMain.gv_Data(i, 0)
FMain.gv_Data(i, 1)
FMain.gv_Data(i, 2)
FMain.gv_Data(i, 3)
FMain.gv_Data(i, 4)
Next
Else
visszhang = SConn.Exec("SELECT * FROM CENTRAL WHERE FName LIKE &1 AND
(FSubs='0' OR FSubs='3') ORDER BY " & detect & " " & direction & ";",
"%" & stext & "%")
For Each visszhang
dis = Insert(visszhang!"FName", visszhang!"FPath",
Round(visszhang!"FSize" / 1048576, -2), visszhang!"FChanged",
visszhang!VName)
Next
FMain.gV.Rows.Count = dis
For i = 0 To dis - 1
FMain.gv_Data(i, 0)
FMain.gv_Data(i, 1)
FMain.gv_Data(i, 2)
FMain.gv_Data(i, 3)
FMain.gv_Data(i, 4)
Next
Endif
Case 3
If FMain.only.Value = True Then
visszhang = SConn.Exec("SELECT * FROM CENTRAL WHERE Category=&1 FName
LIKE &2 AND (FSubs='0' OR FSubs='3') ORDER BY " & detect & " " &
direction & ";", FMain.SelcatBox.Text, "%." & stext & "%")
For Each visszhang
dis = Insert(visszhang!"FName", visszhang!"FPath",
Round(visszhang!"FSize" / 1048576, -2), visszhang!"FChanged",
visszhang!VName)
Next
FMain.gV.Rows.Count = dis
For i = 0 To dis - 1
FMain.gv_Data(i, 0)
FMain.gv_Data(i, 1)
FMain.gv_Data(i, 2)
FMain.gv_Data(i, 3)
FMain.gv_Data(i, 4)
Next
Else
visszhang = FMain.DBconX.Exec("SELECT * FROM CENTRAL WHERE FName LIKE
&1 AND (FSubs='0' OR FSubs='3') ORDER BY " & detect & " " & direction
& ";", "%." & stext & "%")
For Each visszhang
dis = Insert(visszhang!"FName", visszhang!"FPath",
Round(visszhang!"FSize" / 1048576, -2), visszhang!"FChanged",
visszhang!VName)
Next
FMain.gV.Rows.Count = dis
For i = 0 To dis - 1
FMain.gv_Data(i, 0)
FMain.gv_Data(i, 1)
FMain.gv_Data(i, 2)
FMain.gv_Data(i, 3)
FMain.gv_Data(i, 4)
Next
Endif
Case 4
If FMain.only.Value = True Then
visszhang = SConn.Exec("SELECT * FROM CENTRAL WHERE Category=&1 AND
FName=&2 AND FSubs='1' ORDER BY " & detect & " " & direction & ";",
FMain.SelcatBox.Text, stext)
For Each visszhang
dis = Insert(visszhang!"FName", visszhang!"FPath",
Round(visszhang!"FSize" / 1048576, -2), visszhang!"FChanged",
visszhang!VName)
Next
FMain.gV.Rows.Count = dis
For i = 0 To dis - 1
FMain.gv_Data(i, 0)
FMain.gv_Data(i, 1)
FMain.gv_Data(i, 2)
FMain.gv_Data(i, 3)
FMain.gv_Data(i, 4)
Next
Else
visszhang = SConn.Exec("SELECT * FROM CENTRAL WHERE FName=&1 AND
FSubs='1' ORDER BY " & detect & " " & direction & ";", stext)
For Each visszhang
dis = Insert(visszhang!"FName", visszhang!"FPath",
Round(visszhang!"FSize" / 1048576, -2), visszhang!"FChanged",
visszhang!VName)
Next
FMain.gV.Rows.Count = dis
For i = 0 To dis - 1
FMain.gv_Data(i, 0)
FMain.gv_Data(i, 1)
FMain.gv_Data(i, 2)
FMain.gv_Data(i, 3)
FMain.gv_Data(i, 4)
Next
Endif
Case 5
If FMain.only.Value = True Then
visszhang = SConn.Exec("SELECT * FROM CENTRAL WHERE Category=&1 AND
FName LIKE &2 AND FSubs='1' ORDER BY " & detect & " " & direction &
";", FMain.SelcatBox.Text, "%" & stext & "%")
For Each visszhang
dis = Insert(visszhang!"FName", visszhang!"FPath",
Round(visszhang!"FSize" / 1048576, -2), visszhang!"FChanged",
visszhang!VName)
Next
FMain.gV.Rows.Count = dis
For i = 0 To dis - 1
FMain.gv_Data(i, 0)
FMain.gv_Data(i, 1)
FMain.gv_Data(i, 2)
FMain.gv_Data(i, 3)
FMain.gv_Data(i, 4)
Next
Else
visszhang = SConn.Exec("SELECT * FROM CENTRAL WHERE FName LIKE &1 AND
FSubs='1' ORDER BY " & detect & " " & direction & ";", "%" & stext &
"%")
For Each visszhang
dis = Insert(visszhang!"FName", visszhang!"FPath",
Round(visszhang!"FSize" / 1048576, -2), visszhang!"FChanged",
visszhang!VName)
Next
FMain.gV.Rows.Count = dis
For i = 0 To dis - 1
FMain.gv_Data(i, 0)
FMain.gv_Data(i, 1)
FMain.gv_Data(i, 2)
FMain.gv_Data(i, 3)
FMain.gv_Data(i, 4)
Next
Endif
Case 6
If FMain.only.Value = True Then
visszhang = SConn.Exec("SELECT * FROM CENTRAL WHERE Category=&1 AND
FName LIKE &2 AND FSubs='1' ORDER BY " & detect & " " & direction &
";", FMain.SelcatBox.Text, "%." & stext & "%")
For Each visszhang
dis = Insert(visszhang!"FName", visszhang!"FPath",
Round(visszhang!"FSize" / 1048576, -2), visszhang!"FChanged",
visszhang!VName)
Next
FMain.gV.Rows.Count = dis
For i = 0 To dis - 1
FMain.gv_Data(i, 0)
FMain.gv_Data(i, 1)
FMain.gv_Data(i, 2)
FMain.gv_Data(i, 3)
FMain.gv_Data(i, 4)
Next
Else
visszhang = SConn.Exec("SELECT * FROM CENTRAL WHERE FName=&1 ORDER BY
" & detect & " " & direction & ";", stext)
For Each visszhang
dis = Insert(visszhang!"FName", visszhang!"FPath",
Round(visszhang!"FSize" / 1048576, -2), visszhang!"FChanged",
visszhang!VName)
Next
FMain.gV.Rows.Count = dis
For i = 0 To dis - 1
FMain.gv_Data(i, 0)
FMain.gv_Data(i, 1)
FMain.gv_Data(i, 2)
FMain.gv_Data(i, 3)
FMain.gv_Data(i, 4)
Next
Endif
Case 7
If FMain.only.Value = True Then
visszhang = SConn.Exec("SELECT * FROM CENTRAL WHERE Category=&1
FName=&2 ORDERBY " & detect & " " & direction & ";",
FMain.SelcatBox.Text, stext)
For Each visszhang
dis = Insert(visszhang!"FName", visszhang!"FPath",
Round(visszhang!"FSize" / 1048576, -2), visszhang!"FChanged",
visszhang!VName)
Next
FMain.gV.Rows.Count = dis
For i = 0 To dis - 1
FMain.gv_Data(i, 0)
FMain.gv_Data(i, 1)
FMain.gv_Data(i, 2)
FMain.gv_Data(i, 3)
FMain.gv_Data(i, 4)
Next
Else
visszhang = SConn.Exec("SELECT * FROM CENTRAL WHERE FName=&1 ORDER BY
" & detect & " " & direction & ";", stext)
For Each visszhang
dis = Insert(visszhang!"FName", visszhang!"FPath",
Round(visszhang!"FSize" / 1048576, -2), visszhang!"FChanged",
visszhang!VName)
Next
FMain.gV.Rows.Count = dis
For i = 0 To dis - 1
FMain.gv_Data(i, 0)
FMain.gv_Data(i, 1)
FMain.gv_Data(i, 2)
FMain.gv_Data(i, 3)
FMain.gv_Data(i, 4)
Next
Endif
Case 8
If FMain.only.Value = True Then
visszhang = SConn.Exec("SELECT * FROM CENTRAL WHERE Category=&1 FName
LIKE &2 ORDER BY " & detect & " " & direction & ";",
FMain.SelcatBox.Text, "%" & stext & "%")
For Each visszhang
dis = Insert(visszhang!"FName", visszhang!"FPath",
Round(visszhang!"FSize" / 1048576, -2), visszhang!"FChanged",
visszhang!VName)
Next
FMain.gV.Rows.Count = dis
For i = 0 To dis - 1
FMain.gv_Data(i, 0)
FMain.gv_Data(i, 1)
FMain.gv_Data(i, 2)
FMain.gv_Data(i, 3)
FMain.gv_Data(i, 4)
Next
Else
visszhang = SConn.Exec("SELECT * FROM CENTRAL WHERE FName LIKE &1
ORDER BY " & detect & " " & direction & ";", "%" & stext & "%")
For Each visszhang
dis = Insert(visszhang!"FName", visszhang!"FPath",
Round(visszhang!"FSize" / 1048576, -2), visszhang!"FChanged",
visszhang!VName)
Next
FMain.gV.Rows.Count = dis
For i = 0 To dis - 1
FMain.gv_Data(i, 0)
FMain.gv_Data(i, 1)
FMain.gv_Data(i, 2)
FMain.gv_Data(i, 3)
FMain.gv_Data(i, 4)
Next
Endif
Case 9
If FMain.only.Value = True Then
visszhang = SConn.Exec("SELECT * FROM CENTRAL WHERE Category=&1 FName
LIKE &2 ORDER BY " & detect & " " & direction & ";",
FMain.SelcatBox.Text, "%" & stext & "%")
For Each visszhang
dis = Insert(visszhang!"FName", visszhang!"FPath",
Round(visszhang!"FSize" / 1048576, -2), visszhang!"FChanged",
visszhang!VName)
Next
FMain.gV.Rows.Count = dis
For i = 0 To dis - 1
FMain.gv_Data(i, 0)
FMain.gv_Data(i, 1)
FMain.gv_Data(i, 2)
FMain.gv_Data(i, 3)
FMain.gv_Data(i, 4)
Next
Else
visszhang = SConn.Exec("SELECT * FROM CENTRAL WHERE FName LIKE &1
ORDER BY " & detect & " " & direction & ";", "%" & stext & "%")
For Each visszhang
dis = Insert(visszhang!"FName", visszhang!"FPath",
Round(visszhang!"FSize" / 1048576, -2), visszhang!"FChanged",
visszhang!VName)
Next
FMain.gV.Rows.Count = dis
For i = 0 To dis - 1
FMain.gv_Data(i, 0)
FMain.gv_Data(i, 1)
FMain.gv_Data(i, 2)
FMain.gv_Data(i, 3)
FMain.gv_Data(i, 4)
Next
Endif
Case 10
If FMain.only.Value = True Then
If FMain.nuvola > 0
visszhang = SConn.Exec("SELECT * FROM CENTRAL WHERE Category=&1 ORDER
BY " & detect & " " & direction & ";", FMain.SelcatBox.Text)
For Each visszhang
dis = Insert(visszhang!"FName", visszhang!"FPath",
Round(visszhang!"FSize" / 1048576, -2), visszhang!"FChanged",
visszhang!VName)
Next
FMain.gV.Rows.Count = dis
For i = 0 To dis - 1
FMain.gv_Data(i, 0)
FMain.gv_Data(i, 1)
FMain.gv_Data(i, 2)
FMain.gv_Data(i, 3)
FMain.gv_Data(i, 4)
Next
Endif
Else
If FMain.nuvola > 0
visszhang = SConn.Exec("SELECT * FROM CENTRAL ORDER BY " & detect & "
" & direction & ";")
For Each visszhang
dis = Insert(visszhang!"FName", visszhang!"FPath",
Round(visszhang!"FSize" / 1048576, -2), visszhang!"FChanged",
visszhang!VName)
Next
FMain.gV.Rows.Count = dis
For i = 0 To dis - 1
FMain.gv_Data(i, 0)
FMain.gv_Data(i, 1)
FMain.gv_Data(i, 2)
FMain.gv_Data(i, 3)
FMain.gv_Data(i, 4)
Next
Endif
Endif
Case 11
xkl = FMain.list[FMain.list.Row, 0].Text
If FMain.uptf.Value = True Then
visszhang = SConn.Exec("SELECT * FROM CENTRAL WHERE VName=&1 AND FName
LIKE &2 ORDER BY " & detect & " " & direction & ";", xkl, "%" & stext
& "%")
Else
visszhang = SConn.Exec("SELECT * FROM CENTRAL WHERE VName=&1 ORDER BY
" & detect & ";", xkl)
Endif
For Each visszhang
dis = Insert(visszhang!"FName", visszhang!"FPath",
Round(visszhang!"FSize" / 1048576, -2), visszhang!"FChanged", xkl)
Next
FMain.gV.Rows.Count = dis
For i = 0 To dis - 1
FMain.gv_Data(i, 0)
FMain.gv_Data(i, 1)
FMain.gv_Data(i, 2)
FMain.gv_Data(i, 3)
FMain.gv_Data(i, 4)
Next
Case 12
If FMain.list.Rows.Count > 0 Then
If FMain.uptf.Value = True And FMain.archTypeBox.Text = ("ALL") Then
visszhang = SConn.Exec("SELECT * FROM ARCHIVES WHERE Name LIKE &1
ORDER BY NAME " & direction & ";", "%" & stext & "%")
Endif
If FMain.uptf.Value = True And FMain.archTypeBox.Text <> ("ALL") Then
visszhang = SConn.Exec("SELECT * FROM ARCHIVES WHERE Name LIKE &1 AND
Type=&2 ORDER BY NAME " & direction & ";", "%" & stext & "%",
FMain.archTypeBox.Text)
Endif
If FMain.uptf.Value = False And FMain.archTypeBox.Text = ("ALL") Then
visszhang = SConn.Exec("SELECT * FROM ARCHIVES ORDER BY NAME;")
Endif
If FMain.uptf.Value = False And FMain.archTypeBox.Text <> ("ALL") Then
visszhang = SConn.Exec("SELECT * FROM ARCHIVES WHERE Type=&1 ORDER BY
NAME;", FMain.archTypeBox.Text)
Endif
For Each visszhang
dis = Insert(visszhang!"Name", visszhang!"Parent", 0, "-", visszhang!Volume)
Next
If FMain.uptf.Value = True Then
visszhang = SConn.Exec("SELECT * FROM ISO WHERE Name LIKE &1 ORDER BY
NAME " & direction & ";", "%" & stext & "%")
Else
visszhang = SConn.Exec("SELECT * FROM ISO ORDER BY NAME;")
Endif
For Each visszhang
dis = Insert(visszhang!"Name", visszhang!"Holder", 0, "-", visszhang!Volume)
Next
FMain.gV.Rows.Count = dis
For i = 0 To dis - 1
FMain.gv_Data(i, 0)
FMain.gv_Data(i, 1)
FMain.gv_Data(i, 2)
FMain.gv_Data(i, 3)
FMain.gv_Data(i, 4)
Next
Endif
Case 13 ' Let's list the content of a folder
dubl = Split(stext, "#")
visszhang = SConn.Exec("SELECT * FROM CENTRAL WHERE VName=&1 AND
FPath=&2 ORDER BY " & detect & " " & direction & ";", dubl[0],
dubl[1])
For Each visszhang
dis = Insert(visszhang!"FName", visszhang!"FPath",
Round(visszhang!"FSize" / 1048576, -2), visszhang!"FChanged",
visszhang!VName)
Next
FMain.gV.Rows.Count = dis
For i = 0 To dis - 1
FMain.gv_Data(i, 0)
FMain.gv_Data(i, 1)
FMain.gv_Data(i, 2)
FMain.gv_Data(i, 3)
FMain.gv_Data(i, 4)
Next
End Select
SConn.Close()
Return nev.Count
End
Public Sub Trashing()
nev.Clear()
ut.Clear()
nagy.Clear()
mikor.Clear()
kotet.Clear()
End
Public Sub Remove(mit As String)
ut.Remove(mit)
nev.Remove(mit)
kotet.Remove(mit)
mikor.Remove(mit)
nagy.Remove(mit)
End
Public Sub Insert(v1 As String, v2 As String, v3 As Float, v4 As
String, v5 As String) As Integer
nev.Add(v1)
ut.Add(v2)
nagy.Add(v3)
mikor.Add(v4)
kotet.Add(v5)
Return nev.Count
End
Public Sub Name(x As Integer) As String
Return nev[x]
End
Public Sub Volm(x As Integer) As String
Return kotet[x]
End
Public Sub Road(x As Integer) As String
Return ut[x]
End
Public Sub Num() As Integer
Return nev.Count
End
Public Sub Size(x As Integer) As String
Return nagy[x]
End
Public Sub When(x As Integer) As String
Return mikor[x]
End
Public Sub Mhet(szuro As String)
Dim todie As New Integer[]
Dim kotetx As New String[]
Dim utol, m, n As Integer
If (szuro <> Null And szuro <> "") Then 'Deleting after a splitted
string pattern
utol = nev.Length - 1
For m = 0 To utol
If InStr(nev[m], szuro) = 0 Then
todie.Add(m)
Endif
Next
todie.Sort(16)
If FMain.robocop = True Then
FMain.roboBox.Add("#" & szuro)
Endif
For m = 0 To todie.Length - 1
Remove(todie[m])
Next
FMain.gV.Rows.Count -= todie.Length
FMain.gV.Refresh()
todie.Clear()
FMain.hany.Text = FMain.gV.Rows.Count
FMain.combo.Clear()
kotetx.Clear
n = FMain.gV.Rows.Count - 1
For m = 0 To n
kotetx.Add(FMain.gV[m, 1].Text)
Next
kotetx.Sort()
If n > 0 Then
FMain.combo.Add(kotetx[0])
For m = 1 To n
If (kotetx[m - 1] <> kotetx[m]) Then
FMain.combo.Add(kotetx[m])
Endif
Next
Endif
Endif
End
The class Keress is used for search, and its private arrays are
declared at the beginning of the file. This class has only one
instance, and it is responsible for the search through the database.
After the search it handles the results to a GridView called gV,
situated on FMain form.
The problem is: if these arrays are filled with search's hits, the
memory consumption goes up to a certain level, which is O.K. After
that, when I perform another search, with much lower number of found
elements, the memory consumption won't fall although all the arrays
are cleared before filling them with fresh values. Where am I wrong?
I would like to see the memory consumption is in accord with the
number of found elements.
It looks like .Clear is clearing the array from elements, but keeping
its size. Why?
Thank you for the patience!
Csaba
More information about the User
mailing list