Java – Does this cause any memory leaks?

Does this cause any memory leaks?… here is a solution to the problem.

Does this cause any memory leaks?

I’m new to the Java world and wondering if the following will cause any memory leaks around me, reallocated to null. Just wanted to make sure this doesn’t cause any memory leaks because they’re terrible

import android.util.Log;
import android.view.MotionEvent;

public class TouchHandler {
    public TouchHandler() {


static Point down;
    static Point up;
    static boolean isUp = false;
    static boolean isDown = false;

public static void processEvent(MotionEvent event) {
        switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN:
                Log.i("betterinf", "ACTION DOWN");
                down = new Point();
                down.x = (int) event.getX();
                down.y = (int) event.getY();
                isDown = true;


case MotionEvent.ACTION_UP:
                Log.i("betterinf", "ACTION UP");
                down = new Point();
                up.x = (int) event.getX();
                up.y = (int) event.getY();
                isUp = true;


case MotionEvent.ACTION_MOVE:


public static void Update(Long deltaTime) {
        if (isDown && isUp) {
            event has happened
            isDown = false;
            isUp = false;
            down = null;
            up = null;

Point vel = new Point();
            vel.x = down.x - up.x;
            vel.y = down.y - up.y;
            GM.getBallManager().newPlayerBall(down, vel);




The garbage collector in this example will locally handle any allocated memory that is no longer in use. So, no, this won’t give you a memory leak. It’s important to note that you can still cause memory leaks, and I recommend that you understand how to fix these issues to avoid them happening again in the future.

Related Problems and Solutions