I have a class MyClass which contains a large buffer, about 12Mb.
While my application is working, the instance of this class is constantly (50 times per second) updated.
What would be the most memory and performance wise way : to create a new object for each update and let the previous object to be garbage collected or to use the same object always? And, doesn't using the same object create a memory leak?
Or, in pseudo code:
is
MyClass object = new MyClass();
while(appIsRunning)
{
if (getUpdatedObject(object))
doSomething(object);
}
better than
while(appIsRunning)
{
MyClass object = new MyClass();
if (getUpdatedObject(object ))
doSomething(object);
}
I am trying to make this question as common as possible, but I am ready to add any details if needed.