删除jni Android中的变量引用

删除jni Android中的变量引用,android,memory-management,java-native-interface,Android,Memory Management,Java Native Interface,我开发了一个简单的实时壁纸应用程序。在这方面,我使用了两个本机函数,分别名为CaptureWallper和DrawWallper。在这种情况下,捕捉壁纸的功能如下所示 void Java_com_sample_NativeCalls_ captureWallpaper(JNIEnv * env, jobject this){ struct SwsContext *img_convert_ctx; while(av_read_frame(pFormatCtx, &packet)>=

我开发了一个简单的实时壁纸应用程序。在这方面,我使用了两个本机函数,分别名为CaptureWallper和DrawWallper。在这种情况下,捕捉壁纸的功能如下所示

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);
}

之后,我在onDraw函数的java代码中使用这些函数。当一次又一次地调用此方法时,我的ram内存不断增加。我认为任何一个对象的引用都是创建的,而不是销毁的。任何一个意识到这一点的人,请帮助我解决这个问题。

您的问题可能很简单:

  if(img_convert_ctx == NULL) {
    return;
  }
返回时不带
av\u free\u数据包

然而,从你展示的代码中,确实不可能给出答案,因为它没有展示关于不同变量、指针或函数的任何信息