Machineboy空
Memory Leak(메모리 누수) 본문
* 정의
- an unintentional form of memory consumption whereby the developer fails to free an allocated block of memory when no longer needed.
- 프로그램이 작동하며 할당됐던 메모리가 더 이상 사용되지 않는 시점에서도 반환되지 않는 현상입니다. 정상적으로 반환되지 않은 메모리가 계속 누적되면 프로그램에 할당할 수 있는 메모리가 부족해지면서 프로그램이 비정상적으로 작동하거나 크래시가 발생할 수 있습니다.
* Memory Leak 방지 - http 통신 시 활용되는 using문의 쓰임새
IEnumerator CoSendRequest(HttpInfo httpInfo)
{
if (httpInfo.requestType == RequestType.POST)
{
// Memory leak 방지
// 매개변수: 리소스 변수 선언
using (UnityWebRequest req = UnityWebRequest.Post(httpInfo.url, httpInfo.body))
{
//body를 UTF8로 인코딩해준다.
byte[] byteBody = Encoding.UTF8.GetBytes(httpInfo.body);
//upload를 한다.
req.uploadHandler = new UploadHandlerRaw(byteBody);
//header설정을 한다.
req.SetRequestHeader("Content-Type", "application/json");
//요청 성공할 때 까지 잠깐 양보
yield return req.SendWebRequest();
//성공했다면 내용 print, 실패했다면 error 띄우는 함수 만들었다.
RequestResult(req, httpInfo);
//실행 후 자동으로 dispose 처리 해준다.
}
}
}
- object will be automatically disposed of, helping to prevent memory leaks and improve the program's performance.
'Computer > 개념' 카테고리의 다른 글
Git&GitHub 입문 : 2장 깃으로 버전 관리하기 (0) | 2024.07.17 |
---|---|
Git&GitHub 입문 : 1장 Git 시작하기 (0) | 2024.07.15 |
Value vs Reference type (0) | 2023.10.24 |
Action, Delegate, 함수 포인터 (0) | 2023.10.20 |
VM(Virtual Machine) 가상 머신 (0) | 2023.10.18 |