<html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div style="margin: 0px; "><div style="margin: 0px; "><font color="#3d1d81" face="Menlo" size="2">Hi everyone,</font></div><div style="margin: 0px; "><font color="#3d1d81" face="Menlo" size="2"><br></font></div><div style="margin: 0px; "><font color="#3d1d81" face="Menlo" size="2">I use FFMpeg on iOS/armv7 (I just cloned the repository yesterday) and even though I easily managed to make a basic video player (thanks to all the devs by the way, the project is really a technical achievement !), I still have a frustrating memory leak problem.</font></div><div style="margin: 0px; "><font color="#3d1d81" face="Menlo" size="2"><br></font></div><div style="margin: 0px; "><font color="#3d1d81" face="Menlo" size="2">Short version : some memory is not released each time I play (switch to) a new movie in the same run. The amount of leaking memory depends on the movie, the order is 500KB-5MB.</font></div><div style="margin: 0px; "><font color="#3d1d81" face="Menlo" size="2"><br></font></div><div style="margin: 0px; "><font color="#3d1d81" face="Menlo" size="2">In order to better explain the situation, here are the operations I execute to open a new movie (The code is slightly modified to keep only the relevant calls) :</font></div><div style="margin: 0px; "><font color="#3d1d81" face="Menlo" size="2"><br></font></div><div style="margin: 0px; font-size: 10px; font-family: Menlo; color: rgb(112, 61, 170); ">AVFormatContext<span style="color: #000000">*<span class="Apple-tab-span" style="white-space:pre"> </span>Ctx;</span></div><div style="margin: 0px; "><font color="#3d1d81" face="Menlo" size="2">avformat_open_input(&Ctx, <...>, NULL, &Options);</font></div><div style="margin: 0px; "><font color="#3d1d81" face="Menlo" size="2">avformat_find_stream_info(Ctx, NULL);</font></div><div style="margin: 0px; font-size: 10px; font-family: Menlo; color: rgb(79, 129, 135); "><span style="color: rgb(112, 61, 170); ">AVCodecContext</span><span style="color: rgb(0, 0, 0); ">* </span>VCodecCtx<span style="color: #000000"> = </span>Ctx<span style="color: #000000">-></span><span style="color: #703daa">streams</span><span style="color: #000000">[</span>0<span style="color: #000000">]-></span><span style="color: #703daa">codec</span><span style="color: #000000">;</span></div><div style="margin: 0px; "><font color="#3d1d81" face="Menlo" size="2">AVCodec* TargetVideoCodec = avcodec_find_decoder(VCodecCtx->codec_id);</font></div><div style="margin: 0px; "><font color="#3d1d81" face="Menlo" size="2">avcodec_open2(VCodecCtx, TargetVideoCodec, NULL);</font></div><div style="margin: 0px; "><span style="color: rgb(112, 61, 170); font-family: Menlo; font-size: 10px; ">AVFrame</span><span style="font-family: Menlo; font-size: 10px; ">* </span><font color="#3d1d81" face="Menlo" size="2">TargetFrame = avcodec_alloc_frame();</font></div><div style="margin: 0px; "><span style="color: rgb(112, 61, 170); font-family: Menlo; font-size: 10px; ">AVFrame</span><span style="font-family: Menlo; font-size: 10px; ">* </span><font color="#3d1d81" face="Menlo" size="2">TargetFrameRGB = avcodec_alloc_frame();</font></div><div style="margin: 0px; "><font color="#3d1d81" face="Menlo" size="2">int FrameSizeInBytes = avpicture_get_size(PIX_FMT_RGB24, VCodecCtx->width, VCodecCtx->height);</font></div><div style="margin: 0px; "><font color="#3d1d81" face="Menlo" size="2">uint8_t* FrameBuffer = (uint8_t*) av_malloc(FrameSizeInBytes);</font></div><div style="margin: 0px; "><font color="#3d1d81" face="Menlo" size="2">avpicture_fill((AVPicture*) TargetFrameRGB, FrameBuffer, PIX_FMT_RGB24, VCodecCtx->width, VCodecCtx->height);</font></div><div style="margin: 0px; "><span style="font-family: Menlo; font-size: 10px; color: rgb(187, 44, 162); ">struct</span><span style="font-family: Menlo; font-size: 10px; "> </span><span style="color: rgb(112, 61, 170); font-family: Menlo; font-size: 10px; ">SwsContext</span><span style="font-family: Menlo; font-size: 10px; ">* </span><font color="#3d1d81" face="Menlo" size="2">ScaleCtx = sws_getContext(VCodecCtx->width, VCodecCtx->height, VCodecCtx->pix_fmt, VCodecCtx->width, VCodecCtx->height, PIX_FMT_RGB24, SWS_BICUBIC, NULL, NULL, NULL);</font></div><div style="margin: 0px; "><font color="#3d1d81" face="Menlo" size="2"><br></font></div><div style="margin: 0px; "><font color="#3d1d81" face="Menlo" size="2">And here are the functions I call to release all the previous structures :</font></div><div style="margin: 0px; "><font color="#3d1d81" face="Menlo" size="2"><br></font></div><div style="margin: 0px; "><font color="#3d1d81" face="Menlo" size="2">sws_freeContext(ScaleCtx);</font></div><div style="margin: 0px; "><font color="#3d1d81" face="Menlo" size="2">avpicture_free((AVPicture*)TargetFrameRGB);</font></div><div style="margin: 0px; "><font color="#3d1d81" face="Menlo" size="2">av_free(FrameBuffer);</font></div><div style="margin: 0px; "><font color="#3d1d81" face="Menlo" size="2">avcodec_free_frame(&TargetFrame);</font></div><div style="margin: 0px; "><font color="#3d1d81" face="Menlo" size="2">avcodec_free_frame(&TargetFrameRGB);</font></div><div style="margin: 0px; "><font color="#3d1d81" face="Menlo" size="2">avcodec_close(VCodecCtx);</font></div><div style="margin: 0px; "><font color="#3d1d81" face="Menlo" size="2">avformat_close_input(&Ctx);</font></div><div style="margin: 0px; "><font color="#3d1d81" face="Menlo" size="2"><br></font></div><div style="margin: 0px; "><font color="#3d1d81" face="Menlo" size="2">There's no AVPacket management, picture scaling or anything graphical here because I tried to present you the minimal pieces of code for which the problem occurs.</font></div><div style="margin: 0px; "><font color="#3d1d81" face="Menlo" size="2"><br></font></div><div style="margin: 0px; "><font color="#3d1d81" face="Menlo" size="2">Obviously, I didn't release something I asked to be allocated so </font><span style="color: rgb(61, 29, 129); font-family: Menlo; font-size: small; ">I'm sure I've forgot to call a avXXX_free_something but I can't find anything in the sources and I'm quite stuck.</span></div><div style="margin: 0px; "><font color="#3d1d81" face="Menlo" size="2"><br></font></div><div style="margin: 0px; "><font color="#3d1d81" face="Menlo" size="2">Is there anybody who can see what the problem is ?</font></div><div style="margin: 0px; "><font color="#3d1d81" face="Menlo" size="2"><br></font></div><div style="margin: 0px; "><font color="#3d1d81" face="Menlo" size="2"><br></font></div><div style="margin: 0px; "><font color="#3d1d81" face="Menlo" size="2">Thanks.</font></div><div style="margin: 0px; "><font color="#3d1d81" face="Menlo" size="2"><br></font></div><div style="margin: 0px; "><font color="#3d1d81" face="Menlo" size="2">Fulbert.</font></div></div></body></html>