Comparison

๋ฉ”๋ชจ๋ฆฌ ๊ด€๋ฆฌ ๊ธฐ์ˆ ์˜ ๋Œ€๋žต์ ์ธ ๋น„๊ต์ž…๋‹ˆ๋‹ค.

Here is a rough comparison of the memory management techniques.

Pros of Different Memory Management Techniques

  • C์™€ ๊ฐ™์€ ์ˆ˜๋™ ๊ด€๋ฆฌ:
    • ๋Ÿฐํƒ€์ž„ ์˜ค๋ฒ„ํ—ค๋“œ๊ฐ€ ์—†์Œ.
  • JAVA์™€ ๊ฐ™์€ ์ž๋™ํ™” ๊ด€๋ฆฌ:
    • ์™„์ „ํ•œ ์ž๋™ํ™”.
    • ์•ˆ์ „ํ•˜๊ณ  ์ •ํ™•ํ•จ.
  • C++๊ณผ ๊ฐ™์€ ๋ฒ”์œ„ ๊ธฐ๋ฐ˜ ๊ด€๋ฆฌ:
    • ๋ถ€๋ถ„ ์ž๋™ํ™”
    • ๋Ÿฐํƒ€์ž„ ์˜ค๋ฒ„ํ—ค๋“œ๊ฐ€ ์—†์Œ.
  • ๋Ÿฌ์ŠคํŠธ์™€ ๊ฐ™์€ ์ปดํŒŒ์ผ๋Ÿฌ ์ˆ˜ํ–‰ ๋ฒ”์œ„ ๊ธฐ๋ฐ˜ ๊ด€๋ฆฌ:
    • ์ปดํŒŒ์ผ๋Ÿฌ์— ์˜ํ•ด ์ˆ˜ํ–‰๋ฉ๋‹ˆ๋‹ค.
    • ๋Ÿฐํƒ€์ž„ ์˜ค๋ฒ„ํ—ค๋“œ๊ฐ€ ์—†์Šต๋‹ˆ๋‹ค.
    • ์•ˆ์ „ํ•˜๊ณ  ์ •ํ™•ํ•ฉ๋‹ˆ๋‹ค.
  • Manual like C:
    • No runtime overhead.
  • Automatic like Java:
    • Fully automatic.
    • Safe and correct.
  • Scope-based like C++:
    • Partially automatic.
    • No runtime overhead.
  • Compiler-enforced scope-based like Rust:
    • Enforced by compiler.
    • No runtime overhead.
    • Safe and correct.

Cons of Different Memory Management Techniques

  • C์™€ ๊ฐ™์€ ์ˆ˜๋™ ๊ด€๋ฆฌ:
    • ์‚ฌ์šฉ ํ›„ ํ•ด์ œ ๋ฌธ์ œ
    • ์ด์ค‘ ํ•ด์ œ ๋ฌธ์ œ
    • ๋ฉ”๋ชจ๋ฆฌ ๋ˆ„์ˆ˜ ๋ฌธ์ œ
  • JAVA์™€ ๊ฐ™์€ ์ž๋™ํ™” ๊ด€๋ฆฌ:
    • GC์˜ ์ผ์‹œ์ค‘์ง€
    • ์†Œ๋ฉธ์ž ์ง€์—ฐ ๋™์ž‘
  • C++๊ณผ ๊ฐ™์€ ๋ฒ”์œ„ ๊ธฐ๋ฐ˜ ๊ด€๋ฆฌ:
    • ๋ณต์žกํ•˜๋ฉฐ ๊ฐœ๋ฐœ์ž์— ์˜ํ•ด์„œ ์ตœ์ ํ™”๊ฐ€ ํ•„์š”ํ•จ
    • ์‚ฌ์šฉ ํ›„ ํ•ด์ œ ๋ฌธ์ œ ๊ฐ€๋Šฅ์„ฑ ์žˆ์Œ
  • ๋Ÿฌ์ŠคํŠธ์™€ ๊ฐ™์€ ์ปดํŒŒ์ผ๋Ÿฌ ์ˆ˜ํ–‰ ๋ฒ”์œ„ ๊ธฐ๋ฐ˜ ๊ด€๋ฆฌ:
    • ์•ฝ๊ฐ„์˜ ์ดˆ๊ธฐ ๋ณต์žก์„ฑ
    • ์œ ํšจํ•œ ํ”„๋กœ๊ทธ๋žจ(๋กœ์ง)์ด ๊ฑฐ๋ถ€ ๋  ์ˆ˜ ์žˆ์Œ
  • Manual like C:
    • Use-after-free.
    • Double-frees.
    • Memory leaks.
  • Automatic like Java:
    • Garbage collection pauses.
    • Destructor delays.
  • Scope-based like C++:
    • Complex, opt-in by programmer.
    • Potential for use-after-free.
  • Compiler-enforced and scope-based like Rust:
    • Some upfront complexity.
    • Can reject valid programs.