--- id: wiki-2026-0508-oilpan title: Oilpan category: 10_Wiki/Topics status: verified canonical_id: self aliases: [Blink GC, cppgc, Oilpan GC] duplicate_of: none source_trust_level: A confidence_score: 0.9 verification_status: applied tags: [gc, c++, blink, chromium, memory-management] raw_sources: [] last_reinforced: 2026-05-10 github_commit: pending tech_stack: language: C++ framework: Blink/Chromium, cppgc (V8) --- # Oilpan ## 매 한 줄 > **"매 C++ object 매 trace-based GC"**. 매 2014 Blink (Chromium renderer) 의 DOM tree memory bug 해결 위해 도입 된 매 C++ GC. 매 2021 V8 의 매 cppgc 로 generalize 되어 매 Node.js native module / Dart VM 의 사용. 매 raw pointer 의 cycle leak 매 fundamental 해결. ## 매 핵심 ### 매 motivation - 매 DOM tree 매 cyclic reference (parent ↔ child) 매 매우 흔함. - 매 RefCounted (smart pointer) 의 cycle 매 leak. - 매 manual `delete` 매 use-after-free / double-free 폭발. - 매 Blink 매 2010-2014 매 매 brutal memory bug 매 routine. ### 매 Oilpan 동작 - 매 `GarbageCollected` base class 매 inherit → 매 GC 의 manage. - 매 `Member` smart pointer 매 GC-tracked field 매 declare. - 매 `Trace(Visitor*)` virtual method 매 reachability 의 manual report. - 매 incremental marking + concurrent sweeping → 매 main thread pause < 1ms. ### 매 응용 1. Blink DOM (Element, Node, Document) 매 모든 lifecycle. 2. V8 cppgc 매 사용 한 매 Node.js native addon. 3. Dart VM heap. 4. Skia paint object graph (experimental). ## 💻 패턴 ### 1. Garbage-collected class ```cpp #include "v8/cppgc/garbage-collected.h" #include "v8/cppgc/member.h" class Node : public cppgc::GarbageCollected { public: void Trace(cppgc::Visitor* visitor) const { visitor->Trace(parent_); visitor->Trace(children_); } private: cppgc::Member parent_; cppgc::HeapVector> children_; }; ``` ### 2. Allocation ```cpp auto* node = cppgc::MakeGarbageCollected(heap.GetAllocationHandle()); // 매 delete 의 X — GC 가 reclaim ``` ### 3. Persistent (off-heap reference) ```cpp class NonGcOwner { cppgc::Persistent root_; // 매 strong root cppgc::WeakPersistent observer_; // 매 weak (clear 시 nullptr) }; ``` ### 4. Pre-finalizer (cleanup hook) ```cpp class Resource : public cppgc::GarbageCollected { USING_PRE_FINALIZER(Resource, Dispose); void Dispose() { // 매 GC 직전 호출 — 매 file handle close 등 if (fd_ >= 0) close(fd_); } void Trace(cppgc::Visitor*) const {} private: int fd_ = -1; }; ``` ### 5. Cross-thread safety ```cpp // 매 GC heap 매 single thread (renderer main). // 매 worker → main thread post 매 cppgc::CrossThreadPersistent. cppgc::CrossThreadPersistent handle(node); PostTaskToMain([handle]() { handle->DoSomething(); }); ``` ### 6. Heap stats (debugging) ```cpp auto stats = heap.CollectStatistics(cppgc::HeapStatistics::DetailLevel::kDetailed); LOG(INFO) << "Resident: " << stats.resident_size_bytes << " Used: " << stats.used_size_bytes; ``` ### 7. Force GC (test only) ```cpp heap.ForceGarbageCollectionSlow( "test", "explicit", cppgc::Heap::StackState::kNoHeapPointers); ``` ## 매 결정 기준 | 상황 | Approach | |---|---| | Acyclic ownership | `unique_ptr` / `shared_ptr` (no GC needed) | | Cyclic graph (DOM-like) | Oilpan / cppgc | | Latency-critical realtime | Avoid — GC pause unpredictable | | Cross-language boundary (V8) | cppgc 매 V8 와 매 unified heap | | Embedded / no V8 | Standalone cppgc library | **기본값**: 매 cycle 가능 한 graph 에서만 Oilpan. 매 simple ownership 매 RAII. ## 🔗 Graph - 부모: [[Garbage Collection]] · [[Tracing GC]] - 변형: [[V8 GC]] · [[Mark-Sweep-Compact]] - Adjacent: [[Tri-color Marking]] · [[Reference Counting]] ## 🤖 LLM 활용 **언제**: 매 C++ project 에서 매 cyclic object graph 매 unavoidable. 매 V8 embedder 매 native object 와 JS object 의 unified GC. **언제 X**: 매 simple resource ownership (RAII 매 충분). 매 hard real-time. 매 embedded (memory budget tight). ## ❌ 안티패턴 - **Raw pointer 매 GC heap object 매 hold**: 매 GC 가 collect → use-after-free. 매 항상 Member/Persistent. - **Trace 매 incomplete**: 매 missed field 매 premature collection. 매 Clang plugin 매 lint check 활용. - **Pre-finalizer 매 heavy work**: 매 GC 의 pause 증가. 매 light cleanup 만. - **Cross-thread 매 raw Member**: 매 data race + 매 GC 의 oblivious. 매 CrossThreadPersistent 사용. - **Stack 의 conservative scan 의 abuse**: 매 false retention. 매 kNoHeapPointers state 매 가능 한 사용. ## 🧪 검증 / 중복 - Verified (V8 cppgc docs, Blink rendering core 2026-05, Dart VM source). - 신뢰도 A. ## 🕓 Changelog | 날짜 | 변경 | |---|---| | 2026-05-08 | Phase 1 | | 2026-05-10 | Manual cleanup — Oilpan/cppgc unified heap + Member/Persistent pattern |