Option Explicit
Dim VBFlexGridCells() As String
Private Sub store_values()
On Error GoTo store_values_EH
Dim IndexLong As Long
Dim i As Integer
Dim entry As String
Dim rw As Integer
Dim aa As String
Dim bb As String
Dim cc As String
Dim dd As String
Dim ee As String
Dim jj As Integer
Dim ff As String
Dim ll As String
Dim mm As String
Dim nn As String
Dim kk As String
rw = 1
For rw = 0 To 15000
aa = String(10000, "w")
bb = String(125, "w")
cc = String(125, "w")
dd = String(125, "w")
ee = String(125, "w")
ff = String(125, "w")
kk = String(125, "w")
ll = String(125, "w")
mm = String(125, "w")
nn = String(125, "w")
entry = aa & Chr(9) & bb & Chr(9) & cc & Chr(9) & dd & Chr(9) & ee & Chr(9) & ff & Chr(9) & kk & Chr(9) & ll & Chr(9) & mm & Chr(9) & nn
IndexLong = IndexLong + 1
ReDim Preserve VBFlexGridCells(10, IndexLong)
Dim abc() As String
abc = Split(entry, vbTab)
For jj = LBound(abc) To UBound(abc)
VBFlexGridCells(jj, IndexLong) = abc(jj)
Next
Next
Exit Sub
store_values_EH:
MsgBox Err.Description & Space(10) & "store_values"
End Sub
Before the execution of the code above, the memory used by our vb6 program :17,720 KB
After the execution of the code above , the memory used by our vb6 program :386,836 KB
Our approximation of memory usage after code execution :320 MB
Actual memory usage and approximated memory usage are in same range ~300MB
however, when string cc is increased to take in 126 chars there is huge spike in memory usage.
cc = String(126, "w")
The memory used by our vb6 program after code execution:700.04 MB
Our approximation of memory usage after code execution :320 MB
Memory usage shoots from 320 Mb to 700 MB .similarly, when other strings are increased to 126 chars , memory shoots up in the range of GB's and results in "out of memory" errors.Also there seems to be some issue with vb6 string append (http://www.aivosto.com/articles/stringopt2.html "Building huge strings" )
Is there any option to detect and clear (de-allocate) this unused memory in vb6?