Skip to content

Commit

Permalink
Merge "Fix memory leak of SkMovie class"
Browse files Browse the repository at this point in the history
  • Loading branch information
cco3 authored and Android Code Review committed Apr 29, 2011
2 parents 8ebf355 + 08d7778 commit 9fd8e05
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
5 changes: 5 additions & 0 deletions core/jni/android/graphics/Movie.cpp
Expand Up @@ -115,6 +115,10 @@ static jobject movie_decodeByteArray(JNIEnv* env, jobject clazz,
return create_jmovie(env, moov);
}

static void movie_destructor(JNIEnv* env, jobject, SkMovie* movie) {
delete movie;
}

//////////////////////////////////////////////////////////////////////////////////////////////

#include <android_runtime/AndroidRuntime.h>
Expand All @@ -129,6 +133,7 @@ static JNINativeMethod gMethods[] = {
(void*)movie_draw },
{ "decodeStream", "(Ljava/io/InputStream;)Landroid/graphics/Movie;",
(void*)movie_decodeStream },
{ "nativeDestructor","(I)V", (void*)movie_destructor },
{ "decodeByteArray", "([BII)Landroid/graphics/Movie;",
(void*)movie_decodeByteArray },
};
Expand Down
11 changes: 11 additions & 0 deletions graphics/java/android/graphics/Movie.java
Expand Up @@ -46,6 +46,8 @@ public void draw(Canvas canvas, float x, float y) {
public static native Movie decodeByteArray(byte[] data, int offset,
int length);

private static native void nativeDestructor(int nativeMovie);

public static Movie decodeFile(String pathName) {
InputStream is;
try {
Expand All @@ -57,6 +59,15 @@ public static Movie decodeFile(String pathName) {
return decodeTempStream(is);
}

@Override
protected void finalize() throws Throwable {
try {
nativeDestructor(mNativeMovie);
} finally {
super.finalize();
}
}

private static Movie decodeTempStream(InputStream is) {
Movie moov = null;
try {
Expand Down

0 comments on commit 9fd8e05

Please sign in to comment.