tech1guy
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.
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.
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.
ASKER