I used to use my a custom class that is responsible for logging with the following implementation
public class Logger {
public final static boolean DEBUG = true;
public static void d(String tag, String msg) {
if(DEBUG)
Log.d(tag, msg);
}
}
When I release the app I set the flag to false, however I was said that the following method is not that efficient since the Strings
are still being allocated and then deallocated in the memory
the logger being used like that:
Logger.d("tag", "message");
or maybe like that, by doing that the StringBuilder
will be invoked
Logger.d("tag", "server response: " + response + " timing: " + timing);
Is that true, can't the dalvik/compiler optimize it to prevent such behaviour. and if so, is there something I can do to optimize it other than moving the if outside?