|
code
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
How to reorganize this FOR..NEXT loop to prevent the 'out of memory' warning?memory problem. I have investigated the whole subroutine and it shows that a FOR NEXT loop consumes too much memory which isn't released by VB after the loop. Sub ProblemRoutine Dim var7 as string Dim var8 as string Dim rij as long DO For rij = 1 To testgrid.Rows - 1 var7 = testgrid.Cell(flexcpText, rij, 7) var8 = testgrid.Cell(flexcpText, rij, 8) If IsNumeric(var7) And IsNumeric(var8) Then If CLng(var8) = ID_emp And CLng(var7) = Weeknr Then Found = True Exit For End If End If Next rij 'some processing in which more records are added to the testgrid, each row only consumes about 4 Byte LOOP until ... END Sub In case that more than 2000 rows are added to the testgrid, the memory consumption is about 200 Bytes for one FOR-NEXT loop only. How should I change my FOR NEXT loop in order to free the memory consumption? That's a small number of iterations for a "For Next" loop. We don't see
where rows are being added to the grid. I don't see anything in the loop that would consume memory, or where anything can be freed. I would expect a grid with 2000 rows to be a problem. What kind of grid is it? DataGrids don't have a Cell method. Show quote "OK" <o**@xs4all.nl> wrote in message news:e4innYdKIHA.4584@TK2MSFTNGP03.phx.gbl... >I am faced with a strange memory problem by which my source fires an Out >of memory problem. > I have investigated the whole subroutine and it shows that a FOR NEXT loop > consumes too much memory which isn't released by VB after the loop. > > Sub ProblemRoutine > Dim var7 as string > Dim var8 as string > Dim rij as long > > > DO > > > For rij = 1 To testgrid.Rows - 1 > var7 = testgrid.Cell(flexcpText, rij, 7) > var8 = testgrid.Cell(flexcpText, rij, 8) > > If IsNumeric(var7) And IsNumeric(var8) Then > If CLng(var8) = ID_emp And CLng(var7) = Weeknr > Then > Found = True > Exit For > End If > End If > Next rij > > > 'some processing in which more records are added to the > testgrid, each row only consumes about 4 Byte > > LOOP until ... > > END Sub > > In case that more than 2000 rows are added to the testgrid, the memory > consumption is about 200 Bytes for one FOR-NEXT loop only. How should I > change my FOR NEXT loop in order to free the memory consumption? > > > > |
|||||||||||||||||||||||