Object Pooling (오브젝트 풀링)
Relevant source files (관련 소스 파일)
•
Scripts/Editor/Inspector/ObjectPoolComponentInspector.cs
•
Scripts/Editor/Inspector/ReferencePoolComponentInspector.cs
•
Scripts/Runtime/Debugger/DebuggerComponent.ObjectPoolInformationWindow.cs
•
Scripts/Runtime/Debugger/DebuggerComponent.ReferencePoolInformationWindow.cs
•
Scripts/Runtime/Debugger/DebuggerComponent.ReferencePoolInformationWindow.cs.meta
•
Scripts/Runtime/Debugger/DebuggerComponent.RuntimeMemoryInformationWindow.cs
•
Scripts/Runtime/Debugger/DebuggerComponent.RuntimeMemorySummaryWindow.cs
Overview (개요)
오브젝트 풀링(Object Pooling) 은 객체를 반복적으로 생성/삭제하는 대신 재사용하여 메모리 사용과 성능을 최적화하는 디자인 패턴입니다.
Unity 게임에서 오브젝트 풀링은 GC(가비지 컬렉션) 부하 감소, CPU 사용량 절감에 큰 효과가 있으며, 이를 위해 재사용 가능한 객체 풀을 유지합니다.
참고:
C# 참조형 객체를 위한 별도의 시스템은 Reference Pooling 문서를 확인하세요.
Overview and Architecture (개요 및 아키텍처)
Game Framework의 오브젝트 풀링 시스템은 객체 생성, 관리, 재사용을 위한 메커니즘을 제공합니다.
이는 효율적인 오브젝트 생명주기 관리를 위해 여러 컴포넌트로 구성됩니다.
Sources:
Scripts/Editor/Inspector/ObjectPoolComponentInspector.cs 35-46
Scripts/Runtime/Debugger/DebuggerComponent.ObjectPoolInformationWindow.cs 38-42
Object Lifecycle (오브젝트 생명주기)
풀에 속한 객체는 특정 생명주기를 따릅니다. 이를 이해하는 것이 풀링 시스템 활용의 핵심입니다.
객체 상태 종류:
•
Created: 처음 생성되어 풀에 추가된 상태
•
Idle: 풀 안에서 대기 중인 상태 (재사용 가능)
•
In Use: 게임 내에서 활성화되어 사용 중인 상태
•
Released: 풀에서 제거된 상태 (풀 용량 초과 또는 만료 시점 도달 시)
Sources:
Scripts/Editor/Inspector/ObjectPoolComponentInspector.cs 51-100
Key Features (핵심 기능)
Auto-Release Mechanism (자동 반환 메커니즘)
시스템은 주기적으로 미사용 객체를 검사하여 해제할 수 있습니다.
반환 기준은 다음과 같습니다:
•
Auto Release Interval: 검사 주기(초 단위)
•
Expire Time: 미사용 상태로 유지될 수 있는 시간
•
Priority: 공간 확보가 필요할 때 우선 제거할 객체의 우선순위
Sources:
Scripts/Editor/Inspector/ObjectPoolComponentInspector.cs 77-82
Multi-Spawn Support (멀티 스폰 지원)
하나의 객체를 동시에 여러 번 스폰할 수 있도록 설정 가능합니다.
이는 동일 리소스가 여러 장소에 동시에 등장해야 하는 경우 유용합니다.
Sources:
Scripts/Editor/Inspector/ObjectPoolComponentInspector.cs 86-89
Scripts/Runtime/Debugger/DebuggerComponent.ObjectPoolInformationWindow.cs 63-79
Object Locking (객체 잠금)
객체를 잠금(lock) 상태로 설정하여 자동 반환 대상에서 제외할 수 있습니다.
이 기능은 항상 풀에 남아 있어야 하는 필수 객체 관리에 유용합니다.
Sources:
Scripts/Editor/Inspector/ObjectPoolComponentInspector.cs 86-90
Configuring Object Pools (객체 풀 설정)
각 오브젝트 풀은 여러 매개변수로 설정할 수 있습니다:
Parameter | Description (설명) |
Name | 풀의 식별자 |
Type | 관리되는 객체의 타입 |
Auto Release Interval | 미사용 객체 검사 주기 (초 단위) |
Capacity | 풀에서 보관 가능한 최대 객체 수 |
Expire Time | 미사용 객체가 해제되기까지의 시간 |
Priority | 용량 도달 시 어떤 객체를 우선 해제할지 결정 |
Sources:
Scripts/Editor/Inspector/ObjectPoolComponentInspector.cs 75-82
Debugging and Monitoring (디버깅 및 모니터링)
프레임워크는 런타임에서 오브젝트 풀을 디버깅/모니터링할 수 있는 기능을 제공합니다.
Object Pool Information Window (오브젝트 풀 정보 창)
DebuggerComponent의 일부로 제공되며, 다음을 실시간 표시합니다:
•
풀의 개수
•
각 풀의 상세 정보 (이름, 타입, 용량 등)
•
풀 내 개별 객체 정보 (잠금 여부, 사용 상태, 우선순위, 마지막 사용 시각)
이 정보를 통해 풀 크기 문제, 잘못 재활용되는 객체 등을 파악할 수 있습니다.
Sources:
Scripts/Runtime/Debugger/DebuggerComponent.ObjectPoolInformationWindow.cs 30-92
Editor Integration (에디터 통합)
ObjectPoolComponentInspector를 통해 에디터에서도 오브젝트 풀을 관리할 수 있습니다.
제공 기능:
•
풀 상세 정보 확인
•
객체 수동 반환
•
풀 데이터를 CSV로 내보내 분석
Sources:
Scripts/Editor/Inspector/ObjectPoolComponentInspector.cs 25-136
Object Pool Information Display Example (정보 표시 예시)
Sources:
Scripts/Runtime/Debugger/DebuggerComponent.ObjectPoolInformationWindow.cs 44-92
Integration with Game Framework (게임 프레임워크와의 통합)
오브젝트 풀링 시스템은 ObjectPoolComponent를 통해 Game Framework와 통합됩니다.
이를 통해 다른 시스템이 손쉽게 풀을 생성, 접근, 관리할 수 있으며, 전반적인 리소스 사용을 최적화합니다.
Sources:
Scripts/Runtime/Debugger/DebuggerComponent.ObjectPoolInformationWindow.cs 18-22
•
Object Pooling 문서는 Pooling Systems보다 더 세부적으로 GameObject 풀링 메커니즘을 다룬 문서입니다.
•
Reference Pooling은 별도로 다루므로, 여기서는 철저히 Unity 오브젝트 관리에 집중합니다.