Merge "Fix memory leak of SkMovie class"

This commit is contained in:
Conley Owens
2011-04-29 10:00:00 -07:00
committed by Android Code Review
2 changed files with 16 additions and 0 deletions

View File

@@ -115,6 +115,10 @@ static jobject movie_decodeByteArray(JNIEnv* env, jobject clazz,
return create_jmovie(env, moov); return create_jmovie(env, moov);
} }
static void movie_destructor(JNIEnv* env, jobject, SkMovie* movie) {
delete movie;
}
////////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////////
#include <android_runtime/AndroidRuntime.h> #include <android_runtime/AndroidRuntime.h>
@@ -129,6 +133,7 @@ static JNINativeMethod gMethods[] = {
(void*)movie_draw }, (void*)movie_draw },
{ "decodeStream", "(Ljava/io/InputStream;)Landroid/graphics/Movie;", { "decodeStream", "(Ljava/io/InputStream;)Landroid/graphics/Movie;",
(void*)movie_decodeStream }, (void*)movie_decodeStream },
{ "nativeDestructor","(I)V", (void*)movie_destructor },
{ "decodeByteArray", "([BII)Landroid/graphics/Movie;", { "decodeByteArray", "([BII)Landroid/graphics/Movie;",
(void*)movie_decodeByteArray }, (void*)movie_decodeByteArray },
}; };

View File

@@ -46,6 +46,8 @@ public class Movie {
public static native Movie decodeByteArray(byte[] data, int offset, public static native Movie decodeByteArray(byte[] data, int offset,
int length); int length);
private static native void nativeDestructor(int nativeMovie);
public static Movie decodeFile(String pathName) { public static Movie decodeFile(String pathName) {
InputStream is; InputStream is;
try { try {
@@ -57,6 +59,15 @@ public class Movie {
return decodeTempStream(is); return decodeTempStream(is);
} }
@Override
protected void finalize() throws Throwable {
try {
nativeDestructor(mNativeMovie);
} finally {
super.finalize();
}
}
private static Movie decodeTempStream(InputStream is) { private static Movie decodeTempStream(InputStream is) {
Movie moov = null; Movie moov = null;
try { try {