Repeatedly calling MovieRenderQueue leaks RAM

Hi there,
we are repeatedly triggering renderings with the MovieRenderQueue from C++ with some scene modifications inbetween. We now upgraded from Unreal 4.27 to 5.2 and after a couple of hundred calls Unreal crashes, after filling up all the available RAM and the Pagefile (total of 300GB). When skipping the MovieRenderQueue call and just doing our scene modifications memory remains stable. And in 4.27 there was no problem as well. So it appears to have something to do wtih the MovieRenderQueue and Unreal 5.x.

Has anybody encountered anything like this before or any idea how to fix it or work aronud the problem?

Hi,
Unfortunately, we are not aware of issue in this kind of scenario.
Could you give us more information on how you are triggering this movie render queue tasks in C++?

Hi, first of all, thanks a lot for looking into this.

The code responsible for starting the rendering is a method in a UEngineSubsystem that essentially boils down to this:

	UMoviePipelineQueueSubsystem* MovieSubsystem = GEditor->GetEditorSubsystem<UMoviePipelineQueueSubsystem>();
	check(MovieSubsystem);

	UMoviePipelineQueue* Queue = MovieSubsystem->GetQueue();

	Queue->Modify();
	Queue->DeleteAllJobs();
	
	const UMovieRenderPipelineProjectSettings* ProjectSettings = GetDefault<UMovieRenderPipelineProjectSettings>();
	if (ProjectSettings) {
		UMoviePipelineExecutorJob* Job = Queue->AllocateNewJob(
			ProjectSettings->DefaultExecutorJob.TryLoadClass<UMoviePipelineExecutorJob>()
		);
	
		Job->Modify();
                Job->Map = FSoftObjectPath{ GEditor->GetEditorWorldContext().World() };
                Job->SetConfiguration(Config);
                Job->SetSequence(SequencePath);
                Job->JobName = FString::Printf(TEXT("%s|%s|%s"),
                      ShotToken, PassToken, LayerToken);
			
		if (!LastExecutor) {
			TSubclassOf< UMoviePipelineExecutorBase> ExecutorClass =
				ProjectSettings->DefaultLocalExecutor.TryLoadClass<UMoviePipelineExecutorBase>();
			LastExecutor = NewObject<UMoviePipelineExecutorBase>(this, ExecutorClass);

		}
		if (LastExecutor) {

			LastExecutor->OnExecutorErrored().AddUObject(this, &UIGRenderSubsystem::RenderErrorHandler);
			LastExecutor->OnExecutorFinished().AddUObject(this, &UIGRenderSubsystem::RenderCompletedHandler);

			MovieSubsystem->RenderQueueWithExecutorInstance(LastExecutor);
		}
	}

Is there anything else, that has to be done? We have some other customizations too, for example, we added a custom output format, by deriving from MoviePipelineImageSequenceOutputBase.

We ran a couple of more tests in the meantime. We tried to start the MovieRenderQueue manually, and without our custom output format and observed the same increase in RAM usage, that did not go down afterwards, even when running the console command

gc.CollectGarbageEveryFrame 1

to trigger garbage collection. Also, the memory increase was most significant when using postprocess materials. And sometimes we had crashes even way before system memory was full.

If you still have trouble to reproduce our issues, I can also provide you with crash logs or setup a small test scene for you. Just let me know, what you need.

Hello !

Did you get any update regarding this leak ?
I am currently setting up something similar and I’m a bit worried it will impact me as well.

Hi,

Yes, we were able to figure out that it was indeed a bug in the movie render queue, causing it to add RenderTargets to the gc roots and never removing them. The bug was in the engine from 5.0 to 5.2 and is fixed from 5.3 onwards.

However, if a bug leaking ~100mb ram per call goes unnoticed for 3 versions of the
engine, it should be clear that this use case has not a high development/testing priority for most of the engine developers and users. So be prepared to figure things out yourself, and be aware that your mileage may vary.

Hope that helps