Link to home
Start Free TrialLog in
Avatar of RichardKline
RichardKline

asked on

Programming Practice adivce -- Tight Loops and New

Is this code inherently bad?  
The datareader has about 30,000 rows.   At this point, the Cls1 and Cls2 classes perform no operation other than Get and Set values.     Ultimately SQL database updates will be done based upon Cls2Instance values.

The reason that I ask is that VS2005 truly yelled at me while running this in test mode.  I didn't write down the error at the time but, in essence, it had to do with MDAs and running dangerously close to being out of memory.    I watched the Task Manager while the app ran and, indeed, the available workstiaton memory shrunk at a good clip.  

These instantiations are done in a very tight loop.  But will loosen up after the complete code is in place.   I'm assuming that the garbage collector can't keep up right now.

So the questions:
1.  Should class instantiations be done like this?
2.  Is there a way to programmaticly (spelling) dispose of the Class at the end of each loop?
I could just variables and update them upon each loop iteration but.... that seems inelegant.   Each of the two classes has about 45 elements.

Thoughts?

Thank you.
 
           While dr.Read()
                Dim Cls1Instance As New Cls1
                With Cls1Instance
                     ' Assign Values
                End With

                Dim Cls2Instance As New Cls2
                With Cls2Instance
                      ' Assign Values from Cls1Instance
                End With

               ' Update SQL database with Cls2Instance values
            End While
ASKER CERTIFIED SOLUTION
Avatar of Xeavn
Xeavn

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of RichardKline
RichardKline

ASKER

Thanks!

It's an database update app.  Reading from a text file, doing some manipulation magic and then updating a database with new/modified records.

I agree with the other 2 guys. If you wrote Cls1 & Cls2, you could add a method called Clear or Reset or something that would essentially return the object to the same state as when it was created.

GC.Collect will force garbage collection. This would work, however, you have to be careful about how many times you call it as it can have a very negative effect on your app's performance.