-1

I am relatively new to memory management concepts and having programmed a little bit in Java, C++ and Swift, I was curious about the differences between the memory management techniques used by each.

From what I know in Java and Swift, objects can only be created on the heap memory. When the object is out of scope, the reference is magically removed. How does this work? I kinda understand how it works in C++, but I would really appreciate if you could shed some light on how memory management works in Java and Swift.

happy_sisyphus
  • 1,224
  • 1
  • 15
  • 24

1 Answers1

2

For a good introduction to how reference counting differs from garbage collection, see:

https://softwareengineering.stackexchange.com/questions/285333/how-does-garbage-collection-compare-to-reference-counting

For how Swift does this automatically, see:

How does the new automatic reference counting mechanism work?

Community
  • 1
  • 1
colavitam
  • 1,250
  • 1
  • 8
  • 13