In the Lunar Lander example (Provided by Google's Android site), there is a main loop in a method called "run()". Here it is below:
@Override
public void run() {
while (mRun) {
Canvas c = null;
try {
c = mSurfaceHolder.lockCanvas(null);
synchronized (mSurfaceHolder) {
if (mMode == STATE_RUNNING) updatePhysics();
doDraw(c);
}
} finally {
// do this in a finally so that if an exception is thrown
// during the above, we don't leave the Surface in an
// inconsistent state
if (c != null) {
mSurfaceHolder.unlockCanvasAndPost(c);
}
}
}
}
So now, my question is this: Isn't it bad to keep nulling c every loop and thereby causing more garbage collection? Maybe I don't understand this well enough, but why must it be nulled?