---
id: cpp-memory-management
title: "C++ Memory Management"
category: "Programming_Language"
status: "draft"
verification_status: "conceptual"
canonical_id: ""
aliases: ["memory management overview", "when to manage memory", "C++ 메모리 관리"]
duplicate_of: ""
source_trust_level: "B"
confidence_score: 0.84
created_at: 2026-07-04
updated_at: 2026-07-04
review_reason: ""
merge_history: []
tags: ["cpp", "programming-language", "w3schools", "memory-management"]
raw_sources: ["https://www.w3schools.com/cpp/cpp_memory_management.asp"]
applied_in: []
github_commit: ""
---

# [[CPP Memory Management]]

## 🎯 한 줄 통찰 (One-line insight)
The source draws a sharp line between two memory scenarios rather than presenting C++ as "always manual" — normal variables (`int x = 10;`) are ALWAYS handled automatically by the compiler, and manual management only becomes YOUR job when you need to create memory WHILE THE PROGRAM RUNS (e.g. based on user input) — meaning the choice to manage memory manually is triggered by a specific need (unknown-size, runtime-determined data), not a default C++ obligation for every variable. [S1]

## 🧠 핵심 개념 (Core concepts)
- **Automatic memory for normal variables** — `int myNumber = 10;` is fully handled by the compiler; no manual management needed. [S1]
- **`sizeof`** — checks how much memory a type uses, same as C. [S1]
- **Manual management triggers** — needed specifically when creating memory AT RUNTIME (e.g. size depends on user input), not for ordinary declared variables. [S1]
- **Risk of mismanagement** — using too much memory, or forgetting to release it, causes slow performance or crashes. [S1]
- **Preview of the tool** — pointers let you access/change memory directly; the NEXT chapter introduces `new` (create) and `delete` (free) for manual memory. [S1]

## 📖 세부 내용 (Details)
- Confirming basic type sizes via sizeof: `int myInt; float myFloat; double myDouble; char myChar; cout << sizeof(myInt); // 4 cout << sizeof(myDouble); // 8`. [S1]

## ⚖️ 모순 및 업데이트 (Contradictions & updates)
- **수동 메모리 관리는 특정 상황에서만 필요**: 일반 변수는 항상 컴파일러가 자동으로 처리하며, 사용자 입력 기반 등 실행 중 크기가 결정되는 메모리를 만들 때만 수동 관리가 필요하다는 점이 명확히 구분됨. [S1]

## 🛠️ 적용 사례 (Applied in summary)
현재 발견된 실제 적용 사례가 없습니다 — 이 챕터가 개관하는 자동/수동 메모리 관리의 경계가 다음 챕터(new/delete)의 구체적 예제로 이어진다. [S1]

## 💻 코드 패턴 (Code patterns)
Checking the actual byte sizes of C++'s basic types with sizeof (C++):
```cpp
int myInt;
float myFloat;
double myDouble;
char myChar;
cout << sizeof(myInt) << "\n";     // 4 bytes
cout << sizeof(myDouble) << "\n";  // 8 bytes
```

## ✅ 검증 상태 및 신뢰도
- **상태:** draft
- **검증 단계:** conceptual
- **출처 신뢰도:** B (W3Schools — widely used educational reference, not a primary standards body)
- **신뢰 점수:** 0.84
- **중복 검사 결과:** 신규 생성 (New discovery)

## 🔗 지식 그래프 (Knowledge Graph)
- **상위/루트:** [[C++ Tutorial]]
- **관련 개념:** [[CPP Pointers Modify]], [[CPP Memory Management New]], [[C Memory Management]]
- **참조 맥락:** 메모리 관리 개관 — new/delete(Memory Management New) 챕터로 이어짐.

## 📚 출처 (Sources)
- [S1] W3Schools — C++ Memory Management — https://www.w3schools.com/cpp/cpp_memory_management.asp

## 📝 변경 이력 (Change history)
- 2026-07-04: Initial draft synthesized from the W3Schools "C++ Memory Management" page (Astra wiki-curation, P-Reinforce v3.1 format).
