I've read here and there that object reuse is a good thing to do - fewer objects, better garbage collection, faster execution, etc. So instead of doing this:
Foo f1 = new Foo();
f1.doSomething();
Foo f2 = new Foo();
f2.doSomething();
I've been doing this:
Foo f1 = new Foo();
f1.doSomething();
f1 = new Foo();
f1.doSomething();
and patting myself on the back for reusing an object. But lately I've been wondering if this is really buying me anything. So I'm asking the question in hopes of learning - is this object reuse? Is it worth doing? And if it isn't, what is?
Thanks in advance...
Idarke "When you have eliminated the impossible, whatever remains, however
improbable, must be the truth." ~ Arthur Conan Doyle
Foo f1 = new Foo();
f1.doSomething();
Foo f2 = new Foo();
f2.doSomething();
I've been doing this:
Foo f1 = new Foo();
f1.doSomething();
f1 = new Foo();
f1.doSomething();
and patting myself on the back for reusing an object. But lately I've been wondering if this is really buying me anything. So I'm asking the question in hopes of learning - is this object reuse? Is it worth doing? And if it isn't, what is?
Thanks in advance...
Idarke "When you have eliminated the impossible, whatever remains, however
improbable, must be the truth." ~ Arthur Conan Doyle