반응형
C# file 사용후 Cloes는 해주지만,
Unity WebRequest 사용 후도 Close 처럼, Dispose가 Close 역할을 해준다.
https://docs.unity3d.com/ScriptReference/Networking.UnityWebRequest.Dispose.html
Unity - Scripting API: Networking.UnityWebRequest.Dispose
You must call Dispose once you have finished using a UnityWebRequest object, regardless of whether the request succeeded or failed. For safety, it is usually a best practice to employ the using statement to ensure that a [UnityWebRequest] is properly clean
docs.unity3d.com
☝. WebReq 후 Dispose를 해주지 않으면 MemoryLeak이 날 수 도 있음!
대신,
using()
{
}
문을 사용하면 알아서 잘 닫아준다.
using UnityEngine;
using UnityEngine.Networking;
using System.Collections;
public class MyExampleBehaviour : MonoBehaviour
{
public IEnumerator Start()
{
using (UnityWebRequest request = UnityWebRequest.Get("https://my-website.com"))
{
yield return request.Send();
Debug.Log("Server responded: " + request.downloadHandler.text);
}
}
}
반응형
'Unity > Unity 최적화관련' 카테고리의 다른 글
Action, AddLisnear 사용 후 -=, RemoveLinear 해주기 (0) | 2023.03.03 |
---|