Skip to content

Commit 9fd8e05

Browse files
cco3Android Code Review
authored andcommitted
Merge "Fix memory leak of SkMovie class"
2 parents 8ebf355 + 08d7778 commit 9fd8e05

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

core/jni/android/graphics/Movie.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,10 @@ static jobject movie_decodeByteArray(JNIEnv* env, jobject clazz,
115115
return create_jmovie(env, moov);
116116
}
117117

118+
static void movie_destructor(JNIEnv* env, jobject, SkMovie* movie) {
119+
delete movie;
120+
}
121+
118122
//////////////////////////////////////////////////////////////////////////////////////////////
119123

120124
#include <android_runtime/AndroidRuntime.h>
@@ -129,6 +133,7 @@ static JNINativeMethod gMethods[] = {
129133
(void*)movie_draw },
130134
{ "decodeStream", "(Ljava/io/InputStream;)Landroid/graphics/Movie;",
131135
(void*)movie_decodeStream },
136+
{ "nativeDestructor","(I)V", (void*)movie_destructor },
132137
{ "decodeByteArray", "([BII)Landroid/graphics/Movie;",
133138
(void*)movie_decodeByteArray },
134139
};

graphics/java/android/graphics/Movie.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ public void draw(Canvas canvas, float x, float y) {
4646
public static native Movie decodeByteArray(byte[] data, int offset,
4747
int length);
4848

49+
private static native void nativeDestructor(int nativeMovie);
50+
4951
public static Movie decodeFile(String pathName) {
5052
InputStream is;
5153
try {
@@ -57,6 +59,15 @@ public static Movie decodeFile(String pathName) {
5759
return decodeTempStream(is);
5860
}
5961

62+
@Override
63+
protected void finalize() throws Throwable {
64+
try {
65+
nativeDestructor(mNativeMovie);
66+
} finally {
67+
super.finalize();
68+
}
69+
}
70+
6071
private static Movie decodeTempStream(InputStream is) {
6172
Movie moov = null;
6273
try {

0 commit comments

Comments
 (0)