본문 바로가기
프로그래밍/Unity

Unity 메모리 프로파일링

by neive 2023. 1. 30.
728x90

메모리 프로파일링을 시작해 봅시다.. 개발이 어느정도

된 상황이라면 일단 게임을 일정 시간 켜놓고 메모리의

추이를 지켜보고 지속적으로 늘어나는 것이 확인 되면

원인을 찾아봐야겠지요

 

스테이지 진입 직후를 A 스냅샷으로 잡고, 반나절 정도 

자동 진행 상태로 방치한 뒤 B 스냅샷을 찍어 비교했습

니다. 비교 기준은 Unity Memory Profiler의 Memory 

Usage, 특히 Managed Heap, Other Native Memory,

Untracked Memory 증가량입니다.

 

A 3.35GB -> B 6.47GB

 

Managed Heap이 약 2.05GB 증가한 상태. 이 상태에서는

장시간 플레이 중 C# 관리 메모리 쪽에 오브젝트나 데이터

가 계속 남아 있고 전체 메모리 사용량도 크게 증가하는 상

태... 이제 개선을 해봐야겠지요

 

몬스터 리스폰 관리에 오브젝트 풀 사용 시

A 3.29GB -> B 5.05GB

총 메모리가 약 3.29GB → 5.05GB로 증가했고,

Managed Heap 증가폭은 약 1.06GB 수준이었다.

기존에 비해 전체 메모리와 Managed Heap 증가

폭이 줄어들어, 몬스터 생성/삭제 과정에서 발생하

던 메모리 부담을 어느 정도 줄일 수 있었습니다

 

여기서 한걸음 더 나가서 자주 호출 되는 이펙트도

풀 사용 시

A 3.39GB -> B 5.49GB

전체 메모리만 보면 몬스터 풀링만 적용한 버전보다

조금 더 높았지만, Managed Heap 증가폭은 약 252

MB 수준으로 크게 줄었습니다. C# 관리 메모리 관

점에서는 가장 안정적인 결과였는데

 

다만 Other Native Memory 쪽 Reserved 메모리가

약 1.07GB 증가했데 오브젝트 풀링으로 Managed

Heap 증가는 줄 였지만, 풀에 잡아두는 오브젝트와

리소스가 많아지면서 Native/Reserved 메모리 부담

이 커지는 문제가 남았다. 생각보다 긍정적인 효과만

있진 않았던 것.

 

아니.. 그 와중에 그럼에도 이렇게 메모리를 먹는건

이상한데 하고 몬스터를 하나씩 들여다보니

 

 

아니 이게 뭐야.. 일개 잡몹인데 애니 용량이..?

 

 

아니 주인공 캐릭도 이 정도 쓰는데 이게 맞는겁니까

ㅠㅠㅠ 내가 아무리 코드를 개선을 하려고 용을 써도

잡몹이 저렇게 용량을 써버리면... 이렇게 허무하게 

발견!

 

 

 

기타 자료 :

 

https://docs.unity3d.com/kr/2021.3/Manual/ProfilerMemory.html

 

메모리 프로파일러 모듈 - Unity 매뉴얼

Unity에서 애플리케이션의 메모리 사용량을 분석하는 방법에는 다음의 두 가지가 있습니다.

docs.unity3d.com

 

 

https://resources.unity.com/games/ultimate-guide-to-profiling-unity-games

 

Ultimate guide to profiling Unity games

The Ultimate guide to profiling Unity games features best practices from Unity experts on how to profile and improve the performance of your game on any platform.

resources.unity.com

 

 

https://docs.unity3d.com/Packages/com.unity.memoryprofiler@1.0/manual/snapshots-comparison.html

 

Compare two snapshots | Memory Profiler | 1.0.0

Compare two snapshots You can use the Compare Snapshots mode in the Snapshots component to compare two snapshots together. When you enable this mode, select any two snapshots to open them both in a comparison view in the Main component. Make sure to read a

docs.unity3d.com

 

 

https://docs.unity3d.com/Packages/com.unity.memoryprofiler@1.0/manual/find-memory-leaks.html

 

Find memory leaks | Memory Profiler | 1.0.0

Find memory leaks Memory leaks cause your application to perform worse over time and might eventually lead to a crash. Memory leaks typically happen for one of two reasons: Your project lacks code to release an object from memory, which leads to the object

docs.unity3d.com

메모리 누수 찾기

 

 

Resources.UnloadUnusedAssets();
728x90

'프로그래밍 > Unity' 카테고리의 다른 글

Object Pool 에 들어간 class 의 동작  (0) 2023.03.21
Unity MonoSingleton 모노싱글톤  (1) 2023.02.14
Unity 주변 랜덤  (0) 2023.01.29
Unity - Addressable Patch Download  (0) 2022.10.11
유니티 네트워크 상태 얻기  (0) 2022.08.12

댓글