Files
2nd/10_Wiki/Topics/DevOps_and_Security/Memory Management.md
T
Antigravity Agent f8b21af4be Wiki cleanup: error-doc removal, dedup merge, link normalization
10_Wiki/Topics 대규모 정리:
- 오류 캡처/미완성 stub 문서 227개 제거
- 교차폴더 중복 43클러스터 병합 (63파일 → redirect)
- 링크명 정규화: 깨진 링크 수정·redirect 직결·개념 매핑 ~2,400건
- 카테고리 MOC 6개 신규 생성
- Graph 섹션 미해결 related-keyword 링크 10,058건 제거

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-20 23:52:15 +09:00

4.4 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-memory-management Memory Management 10_Wiki/Topics verified self
memory-mgmt
heap-management
none A 0.9 applied
memory
gc
performance
runtime
systems
2026-05-10 pending
language framework
C/JS/Rust V8/JVM/glibc

Memory Management

매 한 줄

"매 program 매 lifetime 동안 의 allocation/deallocation 의 전략". 매 manual (C/C++) ↔ ARC (Swift/ObjC) ↔ tracing GC (V8/JVM) ↔ ownership (Rust) — 매 spectrum 의 각 trade-off — 매 2026 의 mainstream 4 가지 paradigm 의 공존.

매 핵심

매 4 가지 paradigm

  1. Manual: malloc/free, new/delete — 매 control 최대, 매 leak 위험.
  2. Reference counting: ARC, shared_ptr — 매 deterministic, 매 cycle 문제.
  3. Tracing GC: V8, JVM, .NET — 매 productivity, 매 pause.
  4. Ownership: Rust borrow checker — 매 zero-runtime overhead, 매 learning curve.

매 핵심 metric

  • RSS (resident set size): 매 OS 시점.
  • Heap used: 매 runtime 시점.
  • External: 매 native buffer (Node Buffer).
  • Fragmentation: 매 allocate 가능하지만 매 contiguous block 부재.

매 응용

  1. 매 long-running server 의 stability.
  2. 매 game engine 의 frame budget.
  3. 매 embedded 의 RAM 의 limit.

💻 패턴

매 manual (C)

char *buf = malloc(1024);
if (!buf) { perror("malloc"); exit(1); }
// ... use ...
free(buf);
buf = NULL;  // 매 dangling 의 방지

매 RAII (C++)

{
  std::unique_ptr<MyObj> p = std::make_unique<MyObj>();
  // 매 scope exit 매 자동 delete
}
std::shared_ptr<MyObj> sp = std::make_shared<MyObj>();
// 매 ref-count 0 매 free

매 ownership (Rust)

fn take(s: String) { /* 매 drop on end */ }
let owned = String::from("hi");
take(owned);
// println!("{}", owned);  // 매 compile error: moved

매 tracing GC (JS)

let cache = new Map();
cache.set('a', { big: new Array(1e6) });
cache = null;  // 매 GC 의 next cycle 의 reclaim
// 매 WeakMap 매 key 의 GC 자동 cleanup
const wm = new WeakMap();

매 Node memory inspect

const v8 = require('v8');
console.log(v8.getHeapStatistics());
// { total_heap_size: ..., used_heap_size: ..., heap_size_limit: ... }
process.memoryUsage();
// { rss, heapTotal, heapUsed, external, arrayBuffers }

매 leak detection (Node)

node --inspect app.js
# Chrome DevTools → Memory → Take snapshot → 매 sample 3 개 → comparison view
node --heapsnapshot-signal=SIGUSR2 app.js
kill -USR2 $(pgrep node)

매 pool allocator

class Pool {
  std::vector<MyObj*> free_;
public:
  MyObj* acquire() {
    if (free_.empty()) return new MyObj();
    auto* p = free_.back(); free_.pop_back(); return p;
  }
  void release(MyObj* p) { free_.push_back(p); }
};
// 매 hot path 매 alloc 의 amortize

매 arena (Rust bumpalo)

use bumpalo::Bump;
let arena = Bump::new();
let s = arena.alloc(String::from("hi"));
let v = arena.alloc(vec![1, 2, 3]);
// 매 arena drop 매 모두 free — 매 deallocation O(1)

매 결정 기준

상황 Approach
매 systems / kernel manual + sanitizer
매 high-perf game RAII + pool
매 server productive tracing GC + tune
매 safety + perf Rust ownership
매 short-lived bulk arena

기본값: 매 language idiom 따름 — 매 C++ RAII, 매 JS GC, 매 Rust ownership.

🔗 Graph

🤖 LLM 활용

언제: 매 memory leak / OOM 의 hunt 매 paradigm 의 선택. 언제 X: 매 high-level business logic 의 memory 의 의식 안 해도 됨.

안티패턴

  • manual + GC mix 매 over-confidence: 매 native buffer leak.
  • shared_ptr cycle: 매 weak_ptr 의 break.
  • arena 매 long-lived: 매 effective leak.
  • Rust 매 unsafe 의 무분별: 매 borrow checker 의 우회.

🧪 검증 / 중복

  • Verified (V8/JVM/Rust/glibc 2026 documentation).
  • 신뢰도 A.

🕓 Changelog

날짜 변경
2026-05-08 Phase 1
2026-05-10 Manual cleanup — 4가지 메모리 관리 paradigm 비교 + pattern 정리