Will this lead to a memory leak?

I am new to the java world and I was wondering if the next memory leak surrounding me would be reassigning up and down to zero. I just want to make sure that this does not cause memory leaks, because they are bad

import android.graphics.Point;
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;

                break;

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

                break;

            case MotionEvent.ACTION_MOVE:

                break;
        }
    }

    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);
        }

    }

}
+3
source share
4 answers

The garbage collector in this example will appropriately handle any allocated memory that is no longer in use. This way it will not give you a memory leak. It is important to note that you can still create memory leaks, and I suggest you look at how they can be done to avoid them in the future.

+2
source

Java - , . , , , , , .., .

+1

, !

, , bla bla bla .

Java GB, Java ! SO : Java. , .

java :

  • (, / , )

  • - .

  • Any proprietary locking method is beyond the scope of the JVM garbage collector. This may cause a memory leak.

+1
source

Java has a garbage collector. In fact, I saw an error in your code:

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

            break;

change

 down = new Point();

to

 up = new Point();
0
source

Source: https://habr.com/ru/post/1598119/


All Articles