Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memory leak #81

Closed
VLZH opened this issue Oct 12, 2018 · 3 comments
Closed

Memory leak #81

VLZH opened this issue Oct 12, 2018 · 3 comments

Comments

@VLZH
Copy link

VLZH commented Oct 12, 2018

Hello! I have some problem. And I can't resolve it. When I use sws_scale i have a memory leak.
In examples, I show only the main part of the code.

// reader.go
// ...
func (v *VFile) GetFrame() *gmf.Frame {
	f := gmf.NewFrame().
				SetWidth(960).
				SetHeight(480).
				SetFormat(gmf.AV_PIX_FMT_YUV420P)
	if err := f.ImgAlloc(); err != nil {
		log.Fatal(err)
	}
	return f
}
//...
for _, f := range frames {
	tmpFrame = v.GetFrame()
	v.SwsContext.Scale(f, tmpFrame)
	tmpFrame.SetPts(f.Pts())
	tmpFrame.SetPktPts(f.PktPts())
	tmpFrame.SetPktDts(f.PktDts())
	scaledFrames = append(scaledFrames, tmpFrame)
	f.Free() // free source frame
}
// ...

In next part i send scaledFrames through channel to another file(writer.go), create packages from frames:

//writer.go
//....
packets, err = stream.CodecCtx().Encode(f.Frames, f.Flush)
// I know, that in method Encode frames will be released
//...

And as result, i have memory leak. If do not scale frames and only clone data, memory will not leak.

// reader.go (without memory leak)
// ...
for _, f := range frames {
	// example without leak
	tmpFrame = v.GetFrame()
	tmpFrame.Free()
	// example
	tmpFrame = f.CloneNewFrame()
	tmpFrame.SetPts(f.Pts())
	tmpFrame.SetPktPts(f.PktPts())
	tmpFrame.SetPktDts(f.PktDts())
	scaledFrames = append(scaledFrames, tmpFrame)
	f.Free()
}
// ...

I have not checked how work example. Maybe i have problem by wrong version ffmpeg. If i will find some answers i write information bellow.
P.S Sorry for my English)

@VLZH
Copy link
Author

VLZH commented Oct 12, 2018

Another example with memory leak:

for _, f := range frames {
	tmpFrame = v.GetFrame()
	v.SwsContext.Scale(f, tmpFrame)
	tmpFrame.SetPts(f.Pts())
	tmpFrame.SetPktPts(f.PktPts())
	tmpFrame.SetPktDts(f.PktDts())
	tmpFrame.Free()
	scaledFrames = append(scaledFrames, f) // f is not scaled frame
	// f.Free()
}

@3d0c
Copy link
Owner

3d0c commented Mar 22, 2019

Various memory leaks has been fixed with #101

@3d0c 3d0c closed this as completed Mar 22, 2019
@VLZH
Copy link
Author

VLZH commented Apr 24, 2019

@3d0c Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants