DEV Community

Discussion on: Explain reference and value types like I'm five

Collapse
 
cjbrooks12 profile image
Casey Brooks

Good point, that's exactly what's going on with the Java runtime. And it's a good distinction to point out as that behavior is how the garbage collector knows when to clean up objects: when there are no more references pointing to an object, its memory can be freed.

That being said, this is all transparent to the programmer writing Java code, so while there may be multiple references under the hood, to the developer it just looks like a single shared object. You'd never really notice the difference in reference and value types in a local scope, but the behavior of these different types as they are passed between methods becomes significant and important to understand.