【发布时间】:2012-01-20 10:22:17
【问题描述】:
我开发了一个简单的动态壁纸应用程序。其中我使用了两个本地函数,名为 captureWallpaper 和 DrawWallpaper。在那个 Capture 壁纸功能如下所示
void Java_com_sample_NativeCalls_ captureWallpaper(JNIEnv * env, jobject this){
struct SwsContext *img_convert_ctx;
while(av_read_frame(pFormatCtx, &packet)>=0) {
if(packet.stream_index==videoStream) { avcodec_decode_video(pCodecCtx,
pFrame,
&frameFinished,
packet.data,
packet.size);
if(frameFinished) {
if(img_convert_ctx == NULL) {
w = pCodecCtx->width;
h = pCodecCtx->height;
__android_log_print(ANDROID_LOG_DEBUG,
"video.c",
"NDK: Cannot initialize the conversion context!"
);
img_convert_ctx =
sws_getContext(
w, h,
pCodecCtx->pix_fmt,
textureWidth,textureHeight,textureFormat,
SWS_FAST_BILINEAR,
NULL, NULL, NULL
);
if(img_convert_ctx == NULL) {
return;
}
}
sws_scale(img_convert_ctx,
pFrame->data,
pFrame->linesize,
0, pCodecCtx->height,
pFrameConverted->data,
pFrameConverted->linesize);
av_free_packet(&packet);
return;
}
}
av_free_packet(&packet);
}
av_seek_frame(pFormatCtx,videoStream,0,AVSEEK_FLAG_ANY);
}
之后,我在我的 java 代码中的 onDraw 函数中使用了这些函数。当一次又一次地调用这个方法时,我的内存不断增加。我认为任何一个对象的引用都是被创建而不是被破坏的。任何知道这一点的人,请帮助我摆脱困境。
【问题讨论】:
标签: android memory-management java-native-interface