I'm currently trying to avoid calls to GC_CONCURRENT, so I am looking through my main loop. I noticed that I often create a complex object to perform calculations.
So, my question will be to declare that an object as a class field, the opposite of declaring it in methods that use it, helps performance?
Or because my English probably hurt your brain, here's an example code like a field
class myclass{ private MyObject myObject; ... public void myLoopedMethod(...){ myObject = new MyObject(...); myObject.dostuff; }
An example in a method
class myclass{ ... public void myLoopedMethod(...){ MyObject myObject = new MyObject(...); myObject.dostuff; }
The correct volume will be the method, but I doubt that by creating its field, the memory is always freed and allocated in the same place. Is this true and does it help avoid GC calls?
Also, I should probably do something similar, but I wonder if the logic above makes sense.
class myclass{ private MyObject myObject; ... public void myMethod(...){ myObject.setNewValues(...); myObject.dostuff; } }
ggpuz source share