c24165b8bc
에이전트 8종(대화형/프로그래머 C·S/디자이너/설계자/기획자/QA/PD/PM)에게 [공통 기본 능력 + 롤별 Specialty] 2층으로 지식을 주입하기 위한 재분류. 문서 내용·포맷은 무수정, 폴더 이동만 (6,372개 문서 수 보존 확인). - Topic_Programming → Domain_Programming (내부 구조 보존) - Topic_Graphic → Domain_Design - Topic_Business → Domain_Product - Topic_General → Domain_General - _Common 신설: Math(구 Topic_Math_Specialty), Reasoning(구 General/From_Thinking & Reasoning), Reasoning_Creativity(구 General/From_창의성), Communication(Poetic_Blog_Writing + From_writing) - 타 도메인의 From_* 폴더는 유지 (출처 표기일 뿐, 이미 도메인에 맞게 분류된 문서) - 빈 폴더 정리 (memory/procedures) - 에이전트→폴더 매핑은 workspace의 .astra/agent-knowledge-map.json (9개 에이전트) Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
5.7 KiB
5.7 KiB
id, title, category, status, canonical_id, aliases, duplicate_of, source_trust_level, confidence_score, verification_status, tags, raw_sources, last_reinforced, github_commit, tech_stack
| id | title | category | status | canonical_id | aliases | duplicate_of | source_trust_level | confidence_score | verification_status | tags | raw_sources | last_reinforced | github_commit | tech_stack | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| wiki-2026-0508-가비지-컬렉션-garbage-collection | 가비지 컬렉션 (Garbage Collection) | 10_Wiki/Topics | verified | self |
|
none | A | 0.9 | applied |
|
2026-05-10 | pending |
|
가비지 컬렉션 (Garbage Collection)
매 한 줄
"매 도달 불가능 (unreachable) 한 객체를 자동으로 회수하는 runtime memory manager". 1959 LISP의 mark-and-sweep 부터 현대의 ZGC/Shenandoah/G1 까지 — 매 generational + concurrent + region-based 방향으로 진화. 매 sub-millisecond pause 의 실용화 (2024+).
매 핵심
매 GC 의 근본 작업
- Mark: GC root (stack, globals, registers) 부터 reachable graph traversal.
- Sweep / Compact / Copy: unreachable 객체의 회수 + 매 fragmentation 의 처리.
매 주요 알고리즘
- Mark-and-Sweep: 매 simple, 매 fragmentation 발생.
- Mark-Compact: 매 sweep 후 live object 의 compact — fragmentation X.
- Copying (Cheney): 매 from-space → to-space 의 live copy. 매 generational young gen 에 사용.
- Generational: 매 weak generational hypothesis — 매 young die young. 매 young gen frequent + old gen rare.
- Concurrent / Incremental: 매 mutator thread 와 동시 실행 — pause 의 최소화.
- Region-based (G1, ZGC, Shenandoah): 매 heap 의 region 분할 — 매 partial collection.
매 응용
- JVM (G1 default since Java 9, ZGC production since Java 17, Shenandoah).
- V8 (Orinoco — concurrent + parallel + incremental).
- Go (concurrent tri-color mark-sweep, sub-ms pause).
- .NET CLR (generational + LOH).
- CPython (reference counting + cycle detector).
💻 패턴
Tri-color Marking (concurrent GC 의 기반)
# Tri-color invariant: White (unmarked), Gray (marked, children pending), Black (done)
WHITE, GRAY, BLACK = 0, 1, 2
def tri_color_mark(roots, heap):
for obj in heap:
obj.color = WHITE
gray_set = set()
for r in roots:
r.color = GRAY
gray_set.add(r)
while gray_set:
obj = gray_set.pop()
for child in obj.refs:
if child.color == WHITE:
child.color = GRAY
gray_set.add(child)
obj.color = BLACK
# White = unreachable -> sweep
return [o for o in heap if o.color == WHITE]
Write Barrier (concurrent GC 의 invariant 유지)
// Dijkstra-style: black -> white write 발생 시 child를 gray로 승격
void write_barrier(Object* parent, Object** field, Object* new_val) {
if (parent->color == BLACK && new_val && new_val->color == WHITE) {
new_val->color = GRAY;
gray_queue_push(new_val);
}
*field = new_val;
}
Generational Allocation (bump allocator)
struct YoungGen { start: *mut u8, top: *mut u8, end: *mut u8 }
impl YoungGen {
fn alloc(&mut self, size: usize) -> Option<*mut u8> {
unsafe {
let new_top = self.top.add(size);
if new_top > self.end { return None; } // trigger minor GC
let p = self.top;
self.top = new_top;
Some(p)
}
}
}
Reference Counting + Cycle Detection (CPython)
class Obj:
def __init__(self):
self.refcount = 1
def incref(self): self.refcount += 1
def decref(self):
self.refcount -= 1
if self.refcount == 0:
for child in self.refs: child.decref()
free(self)
# Cycle: a.refs=[b], b.refs=[a] -> refcount 영원히 >0 -> cycle collector 필요
Finalizer (resource cleanup, careful)
// Java AutoCloseable + try-with-resources >>> finalize() (deprecated in Java 9+)
try (var conn = DriverManager.getConnection(url)) {
// use conn
} // auto-close, deterministic
Soft / Weak / Phantom Reference
WeakReference<Cache> ref = new WeakReference<>(cache);
// GC가 free하면 ref.get() == null. Cache 구현에 자주 사용
G1 / ZGC tuning (JVM)
java -XX:+UseZGC -Xmx16g -XX:+UseLargePages MyApp
# ZGC: <1ms pause, multi-TB heap (Java 21+)
java -XX:+UseG1GC -XX:MaxGCPauseMillis=200 MyApp
# G1: pause-target driven, default since Java 9
매 결정 기준
| 상황 | Approach |
|---|---|
| Low-latency service (<10ms p99) | ZGC, Shenandoah, Go GC |
| Throughput batch | Parallel GC (JVM), G1 |
| Embedded / no-GC | Rust, C++ RAII |
| Predictable real-time | No GC + arena allocator |
| Reference cycles 빈번 | tracing GC > refcount |
기본값: 매 modern JVM 의 G1 (or ZGC for >4GB heap), Go 의 default concurrent collector.
🔗 Graph
- 부모: 메모리 관리
- 변형: Reference Counting
- 응용: V8 Engine
- Adjacent: Memory Leak · Heap
🤖 LLM 활용
언제: GC tuning, OOM 분석, GC log 해석, allocation pattern 최적화. 언제 X: 매 hot loop allocation 미세조정 — profiler (async-profiler, pprof) 가 우선.
❌ 안티패턴
- System.gc() 호출: hint 일 뿐, full GC 강제로 pause 유발.
- finalize() 의존: 매 deprecated. AutoCloseable 사용.
- Large object 의 young gen 할당 가정: TLAB overflow → tenuring promotion 발생.
- WeakReference cache 의 무한 신뢰: 매 GC pressure 시 즉시 회수 — cold start.
🧪 검증 / 중복
- Verified (Jones et al. The Garbage Collection Handbook 2nd ed., OpenJDK ZGC docs 2024).
- 신뢰도 A.
🕓 Changelog
| 날짜 | 변경 |
|---|---|
| 2026-05-08 | Phase 1 |
| 2026-05-10 | Manual cleanup — GC algorithms + tri-color + JVM/Go tuning patterns |