Link to home
Start Free TrialLog in
Avatar of tech1guy
tech1guyFlag for United States of America

asked on

Singleton pattern in loop

Hi there,

I am processing a loop with around 1 million records i.e looping around 1 million times. I am creating number of objects within loop. I do NOT want to declare local variables outside the loop, but want to get maximum performance and minimum memory.

So, I am thinking of creating a Singleton CLASS which will hold all the variables/objects that needs to be declared and initialited within loop each time. Now, I will implement Singleton pattern on this class. In other words, Singleton object will be acquired for each run of the loop. Is this a valid option using which I can get maximum performance and minimum memory.
ASKER CERTIFIED SOLUTION
Avatar of iUsername
iUsername

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 tech1guy

ASKER

but I need to RESET the variables/objects within the Singleton class for each loop run.
Avatar of iUsername
iUsername

hmm, well, I don't really know what it means to "reset" the object in the singleton object.

In some cases it is better to simply create a new object (and dispose the last one), in other cases it is better to "reset' an object. depends on the object itself.