I Have a class called car, this class have multiple methods (about 30) to handle things such: starting car, stopping, opening doors ...
- The problem is that my program have thousands of instances of the class car. I noticed I can refactor the class into having member variables that define each instance of a car class, and for the methods they can be made into static methods that takes the instance of the car class as parameter and do the necessary things on it.
- My question is: is static methods going to be better on memory usage or the refactoring doesn't worth it? in other words is using non-static methods going to take up memory for each instance of the car class?
thisparameter will be optimized out. In your case there will be no difference at all, as you anyway need to pass the parameter. Just use the option that fits best with the semantics, most likely an instance method.