From 7f1498cd8e2964606c896e0f7cf88c5e3d423923 Mon Sep 17 00:00:00 2001 From: Sam Carlberg Date: Mon, 10 Oct 2016 12:30:34 -0400 Subject: [PATCH] Fix massive memory leak in previews (#679) (#680) * Fix massve memory leak in lines previews * Fix memory leak in blobs preview --- .../edu/wpi/grip/ui/preview/BlobsSocketPreviewView.java | 4 +++- .../edu/wpi/grip/ui/preview/LinesSocketPreviewView.java | 8 ++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/ui/src/main/java/edu/wpi/grip/ui/preview/BlobsSocketPreviewView.java b/ui/src/main/java/edu/wpi/grip/ui/preview/BlobsSocketPreviewView.java index b282252c85..d60470ad05 100644 --- a/ui/src/main/java/edu/wpi/grip/ui/preview/BlobsSocketPreviewView.java +++ b/ui/src/main/java/edu/wpi/grip/ui/preview/BlobsSocketPreviewView.java @@ -38,6 +38,7 @@ public class BlobsSocketPreviewView extends SocketPreviewView { private final ImageView imageView = new ImageView(); private final Label infoLabel = new Label(); private final Mat tmp = new Mat(); + private final Point point = new Point(); private final GripPlatform platform; @SuppressWarnings("PMD.ImmutableField") @SuppressFBWarnings(value = "IS2_INCONSISTENT_SYNC", @@ -91,7 +92,8 @@ private void convertImage() { if (!blobsReport.getBlobs().isEmpty()) { // For each line in the report, draw a line along with the starting and ending points for (BlobsReport.Blob blob : blobsReport.getBlobs()) { - final Point point = new Point((int) blob.x, (int) blob.y); + point.x((int) blob.x); + point.y((int) blob.y); circle(tmp, point, (int) (blob.size / 2), Scalar.WHITE, 2, LINE_8, 0); } } diff --git a/ui/src/main/java/edu/wpi/grip/ui/preview/LinesSocketPreviewView.java b/ui/src/main/java/edu/wpi/grip/ui/preview/LinesSocketPreviewView.java index 85985464a6..cf9d8ae4d9 100644 --- a/ui/src/main/java/edu/wpi/grip/ui/preview/LinesSocketPreviewView.java +++ b/ui/src/main/java/edu/wpi/grip/ui/preview/LinesSocketPreviewView.java @@ -40,6 +40,8 @@ public class LinesSocketPreviewView extends SocketPreviewView { private final ImageView imageView = new ImageView(); private final Label infoLabel = new Label(); private final Mat tmp = new Mat(); + private final Point startPoint = new Point(); + private final Point endPoint = new Point(); private final GripPlatform platform; @SuppressWarnings("PMD.ImmutableField") @SuppressFBWarnings(value = "IS2_INCONSISTENT_SYNC", @@ -99,8 +101,10 @@ private void convertImage() { // For each line in the report, draw a line along with the starting and ending points for (LinesReport.Line line : lines) { - final Point startPoint = new Point((int) line.x1, (int) line.y1); - final Point endPoint = new Point((int) line.x2, (int) line.y2); + startPoint.x((int) line.x1); + startPoint.y((int) line.y1); + endPoint.x((int) line.x2); + endPoint.y((int) line.y2); line(input, startPoint, endPoint, Scalar.WHITE, 2, LINE_8, 0); circle(input, startPoint, 2, Scalar.WHITE, 2, LINE_8, 0); circle(input, endPoint, 2, Scalar.WHITE, 2, LINE_8, 0);