mirror of
https://github.com/opencv/opencv.git
synced 2026-07-29 07:13:02 +04:00
Merge branch 4.x
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
// This file is part of OpenCV project.
|
||||
// It is subject to the license terms in the LICENSE file found in the top-level directory
|
||||
// of this distribution and at http://opencv.org/license.html
|
||||
|
||||
#include "opencv2/core.hpp"
|
||||
|
||||
#define LOG_TAG "org.opencv.core.CleanableMat"
|
||||
#include "common.h"
|
||||
#include <iostream>
|
||||
|
||||
using namespace cv;
|
||||
|
||||
extern "C" {
|
||||
//
|
||||
// native support for java finalize() or cleaners
|
||||
// static void CleanableMat::n_delete( __int64 self )
|
||||
//
|
||||
|
||||
JNIEXPORT void JNICALL Java_org_opencv_core_CleanableMat_n_1delete
|
||||
(JNIEnv*, jclass, jlong self);
|
||||
|
||||
JNIEXPORT void JNICALL Java_org_opencv_core_CleanableMat_n_1delete
|
||||
(JNIEnv*, jclass, jlong self)
|
||||
{
|
||||
// LOGD("CleanableMat.n_delete() called\n");
|
||||
delete (Mat*) self;
|
||||
}
|
||||
}
|
||||
@@ -2114,22 +2114,6 @@ JNIEXPORT jlong JNICALL Java_org_opencv_core_Mat_n_1zeros__I_3II
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//
|
||||
// native support for java finalize()
|
||||
// static void Mat::n_delete( __int64 self )
|
||||
//
|
||||
|
||||
JNIEXPORT void JNICALL Java_org_opencv_core_Mat_n_1delete
|
||||
(JNIEnv*, jclass, jlong self);
|
||||
|
||||
JNIEXPORT void JNICALL Java_org_opencv_core_Mat_n_1delete
|
||||
(JNIEnv*, jclass, jlong self)
|
||||
{
|
||||
delete (Mat*) self;
|
||||
}
|
||||
|
||||
} // extern "C"
|
||||
|
||||
namespace {
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
package org.opencv.core;
|
||||
|
||||
import java.lang.ref.Cleaner;
|
||||
|
||||
public abstract class CleanableMat {
|
||||
// A native memory cleaner for the OpenCV library
|
||||
public static Cleaner cleaner = Cleaner.create();
|
||||
|
||||
protected CleanableMat(long obj) {
|
||||
if (obj == 0)
|
||||
throw new UnsupportedOperationException("Native object address is NULL");
|
||||
|
||||
nativeObj = obj;
|
||||
|
||||
// The n_delete action must not refer to the object being registered. So, do not use nativeObj directly.
|
||||
long nativeObjCopy = nativeObj;
|
||||
cleaner.register(this, () -> n_delete(nativeObjCopy));
|
||||
}
|
||||
|
||||
private static native void n_delete(long nativeObj);
|
||||
|
||||
public final long nativeObj;
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package org.opencv.core;
|
||||
|
||||
public abstract class CleanableMat {
|
||||
|
||||
protected CleanableMat(long obj) {
|
||||
if (obj == 0)
|
||||
throw new UnsupportedOperationException("Native object address is NULL");
|
||||
|
||||
nativeObj = obj;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void finalize() throws Throwable {
|
||||
n_delete(nativeObj);
|
||||
super.finalize();
|
||||
}
|
||||
|
||||
private static native void n_delete(long nativeObj);
|
||||
|
||||
public final long nativeObj;
|
||||
}
|
||||
Reference in New Issue
Block a user