Thanks, but this was not the problem. My whole database is only 500KB, and the tables used in this specific subroutine is less than 20% of that - so maybe 100KB.
I have found the problem to be multiple use of the same cursor inside the loop. I had:
cur = SQL1.ExecQuery2(SELECT some stuff from a table...)
and then later in the loop I redefined cur
cur = SQL1.ExecQuery2(SELECT other stuff from another table...)
at the end of the loop I cleared cur, but it did not solve the problem.
When I changed the second instance to cur1 (dim'ed upfront) and cleared it inside the end of the loop, the problem went away.
This almost looks like a bug to me... if you redefine a cursor before clearing it, it seems to stay in memory, even if you clear it afterwards.
To summarize:
This runs into a problem with a big loop size (> 500 records in my case)
Dim Rows As Int
Rows = Cursor1.RowCount
'Fill Data
For row = 0 To Rows - 1
Cursor1.Position = row
Dim cur As Cursor
cur = SQL1.ExecQuery2(SELECT some stuff from a table...)
cur.Position = 0
' do something with cur
cur = SQL1.ExecQuery2(SELECT other stuff from another table...)
cur.Position = 0
' do something with cur
cur.Close
Next
This works fine even with more than 6000 records:
Dim Rows As Int
Rows = Cursor1.RowCount
'Fill Data
For row = 0 To Rows - 1
Cursor1.Position = row
Dim cur As Cursor
Dim cur1 As Cursor
cur = SQL1.ExecQuery2(SELECT some stuff from a table...)
cur.Position = 0
' do something with cur
cur1 = SQL1.ExecQuery2(SELECT other stuff from another table...)
cur1.Position = 0
' do something with cur1
cur.Close
cur1.Close
Next
Moral of the story: Don't redefine a cursor inside a loop - it creates a memory leak!