I am using unity's Photocapture Object to take videos with hololens. I wrote the code based on the official sample code, but I changed the process in the update function to take multiple images instead of just one.
https://docs.unity3d.com/2018.4/Documentation/Manual/windowsholographic-photocapture.html
However, when I run this code, it eventually runs out of pagefile.sys, goes out of memory, and aborts. I've searched and found that most of the memory leaks are caused by texture 2d, but in this code, they occur even though I omit them. Furthermore, the unity profiler does not show any gradual increase in memory usage after the code is executed. What could be the cause? I would appreciate it if you could tell me.

using UnityEngine;
using System;
using System.Linq;
using UnityEngine.XR;
using UnityEngine.Windows.WebCam;
using System.Threading.Tasks;
using UnityEngine.Networking;
using System.Text;
using System.IO;
using System.Net;
using System.Collections;
using System.Collections.Generic;
public class photocap : MonoBehaviour
{
PhotoCapture PhotoCapture = null;
Texture2D targetTexture = null;
Resolution cameraResolution;
Renderer quadRenderer;
float dt = 0;
void Start()
{
cameraResolution = PhotoCapture.SupportedResolutions.OrderByDescending((res) => res.width * res.height).First();
GameObject quad = GameObject.CreatePrimitive(PrimitiveType.Quad);
quad.transform.localScale = new Vector3(0.2f, 0.2f, 0.2f);
quadRenderer = quad.GetComponent<Renderer>() as Renderer;
quadRenderer.material = new Material(Shader.Find("Unlit/Texture"));
quad.transform.parent = this.transform;
quad.transform.localPosition = new Vector3(0.0f, 0.0f, 0.3f);
}
async void StartCapture()
{
PhotoCapture.CreateAsync(false, delegate (PhotoCapture captureObject)
{
PhotoCapture = captureObject;
CameraParameters cameraParameters = new CameraParameters();
cameraParameters.hologramOpacity = 0.0f;
cameraParameters.cameraResolutionWidth = cameraResolution.width;
cameraParameters.cameraResolutionHeight = cameraResolution.height;
cameraParameters.pixelFormat = CapturePixelFormat.BGRA32;
PhotoCapture.StartPhotoModeAsync(cameraParameters, delegate (PhotoCapture.PhotoCaptureResult result)
{
PhotoCapture.TakePhotoAsync(OnCapturedPhotoToMemory);
});
});
}
void OnCapturedPhotoToMemory(PhotoCapture.PhotoCaptureResult result, PhotoCaptureFrame photoCaptureFrame)
{
PhotoCapture.StopPhotoModeAsync(OnStoppedPhotoMode);
}
void OnStoppedPhotoMode(PhotoCapture.PhotoCaptureResult result)
{
PhotoCapture.Dispose();
PhotoCapture = null;
}
void Update()
{
dt += Time.deltaTime;
if (dt > 3)
{
dt = 0.0f;
StartCapture();
}
}
}