Good morning SO,
I have a class that contains the following static array:
public static ResultObject[] ResultArray = new ResultObject[500];
In my program, there are 12million instances of this class that all add to this array. I’m getting a OutOfMemoryException and think this might be the reason why.
Is there any way I can manage the memory being used by this array better so I won’t get this exception? If not, which is faster, writing to a file or database?
I’d prefer to hold this data in memory, but if that is the cause of my problem, then I’ll have to try something else.
Thanks!
If ResultObject is static, then you should only have one instance of it, even if you have millions of instances of the class. As others have suggested, double-check that the memory problem isn’t being caused by something else in your class.
If you’re certain the memory problem is related to ResultObject, check carefully to see what you’re doing with this class. For example are you doing anything that might result in a copy of ResultObject being made, for each of those 12 million instances?