# Memory Management (Rust) > Stack vs heap, allocator, Drop trait, RAII, Rc 사이클로 인한 메모리 누수, Pin - 20 면접 질문 - Senior - [면접 질문: Rust](https://sharpskill.dev/ko/technologies/rust/interview-questions.md) ## 1. Rust에서 i32나 bool 같은 기본 타입의 지역 변수는 어디에 저장됩니까? **답변** 기본 타입의 지역 변수는 stack에 저장됩니다. stack은 LIFO(Last In, First Out) 원칙으로 동작하기 때문에 매우 빠른 할당과 해제를 제공합니다. 기본 타입은 컴파일 타임에 크기를 알 수 있으므로 컴파일러가 현재 함수의 stack frame에 필요한 공간을 예약할 수 있습니다. ## 2. 단일 소유자로 heap에 값을 할당하려면 어떤 smart pointer를 사용해야 합니까? **답변** Box는 heap에 데이터를 할당하기 위한 가장 단순한 smart pointer입니다. 단일 소유권을 보장하며 Box가 scope를 벗어나면 자동으로 메모리를 해제합니다. Box는 컴파일 타임에 크기를 알 수 없는 타입, stack에 복사하고 싶지 않은 큰 구조체, 또는 재귀적 타입에 유용합니다. ## 3. Rust의 RAII(Resource Acquisition Is Initialization) 패턴이란 무엇입니까? **답변** RAII는 리소스(메모리, 파일, 연결)를 객체 생성 시 획득하고 소멸 시 자동으로 해제하는 패턴입니다. Rust에서는 값이 scope를 벗어날 때 자동으로 호출되는 Drop trait를 통해 이를 수행합니다. 이 패턴은 어떤 리소스도 잊히지 않도록 보장하며 메모리 누수를 방지합니다. ## 17개 추가 질문 이용 가능 - Rust에서 Drop trait는 언제 자동으로 호출됩니까? - Rust에서 Rc로 메모리 누수(memory leak)를 어떻게 만들 수 있습니까? 무료로 가입하기: https://sharpskill.dev/ko/login ## 기타 Rust 면접 주제 - [Rust 기초](https://sharpskill.dev/ko/technologies/rust/interview-questions/rust-basics.md): 25개 질문, Junior - [Ownership & Borrowing](https://sharpskill.dev/ko/technologies/rust/interview-questions/ownership-borrowing.md): 22개 질문, Junior - [Structs & Enums](https://sharpskill.dev/ko/technologies/rust/interview-questions/structs-enums.md): 20개 질문, Junior - [에러 처리](https://sharpskill.dev/ko/technologies/rust/interview-questions/error-handling.md): 18개 질문, Junior - [컬렉션](https://sharpskill.dev/ko/technologies/rust/interview-questions/collections.md): 20개 질문, Junior - [모듈과 패키지](https://sharpskill.dev/ko/technologies/rust/interview-questions/modules-packages.md): 18개 질문, Junior - [Traits](https://sharpskill.dev/ko/technologies/rust/interview-questions/traits.md): 22개 질문, Mid-Level - [Generics](https://sharpskill.dev/ko/technologies/rust/interview-questions/generics.md): 20개 질문, Mid-Level - [Lifetimes](https://sharpskill.dev/ko/technologies/rust/interview-questions/lifetimes.md): 20개 질문, Mid-Level - [Iterators & Closures](https://sharpskill.dev/ko/technologies/rust/interview-questions/iterators-closures.md): 22개 질문, Mid-Level - [Smart Pointers](https://sharpskill.dev/ko/technologies/rust/interview-questions/smart-pointers.md): 22개 질문, Mid-Level - [Concurrency Basics](https://sharpskill.dev/ko/technologies/rust/interview-questions/concurrency-basics.md): 20개 질문, Mid-Level - [async/await](https://sharpskill.dev/ko/technologies/rust/interview-questions/async-await.md): 22개 질문, Mid-Level - [Testing](https://sharpskill.dev/ko/technologies/rust/interview-questions/testing.md): 18개 질문, Mid-Level - [Cargo & Ecosystem](https://sharpskill.dev/ko/technologies/rust/interview-questions/cargo-ecosystem.md): 18개 질문, Mid-Level - [Pattern Matching](https://sharpskill.dev/ko/technologies/rust/interview-questions/pattern-matching.md): 18개 질문, Mid-Level - [매크로](https://sharpskill.dev/ko/technologies/rust/interview-questions/macros.md): 20개 질문, Mid-Level - [Serde와 직렬화](https://sharpskill.dev/ko/technologies/rust/interview-questions/serde-serialization.md): 20개 질문, Mid-Level - [Unsafe Rust](https://sharpskill.dev/ko/technologies/rust/interview-questions/unsafe-rust.md): 20개 질문, Senior - [고급 트레잇](https://sharpskill.dev/ko/technologies/rust/interview-questions/advanced-traits.md): 22개 질문, Senior - [고급 lifetime](https://sharpskill.dev/ko/technologies/rust/interview-questions/advanced-lifetimes.md): 20개 질문, Senior - [Type System](https://sharpskill.dev/ko/technologies/rust/interview-questions/type-system.md): 20개 질문, Senior - [Tokio & Async I/O](https://sharpskill.dev/ko/technologies/rust/interview-questions/tokio-async.md): 22개 질문, Senior - [성능 최적화](https://sharpskill.dev/ko/technologies/rust/interview-questions/performance-optimization.md): 20개 질문, Senior - [Web Frameworks](https://sharpskill.dev/ko/technologies/rust/interview-questions/web-frameworks.md): 22개 질문, Senior - [Database Integration](https://sharpskill.dev/ko/technologies/rust/interview-questions/database-integration.md): 20개 질문, Senior - [Rust 디자인 패턴](https://sharpskill.dev/ko/technologies/rust/interview-questions/design-patterns.md): 20개 질문, Senior --- Source: SharpSkill (https://sharpskill.dev), tech interview preparation for your real stack. HTML version of this page: https://sharpskill.dev/ko/technologies/rust/interview-questions/memory-management