interview Prep - What is Java Garbage Collection.docx - What is Java Garbage Collection How It Works Best Practices Tutorials and More Stackify

interview Prep - What is Java Garbage Collection.docx -...

This preview shows page 1 - 3 out of 4 pages.

What is Java Garbage Collection? How It Works, Best Practices, Tutorials, and More Stackify May 11, 2017 Developer Tips, Tricks & Resources At Stackify, we battle our fair share of code performance problems too, including issues surrounding Java garbage collection. In this post, we’ll take a look at Java garbage collection, how it works, and why it matters. A Definition of Java Garbage Collection Java garbage collection is the process by which Java programs perform automatic memory management. Java programs compile to bytecode that can be run on a Java Virtual Machine, or JVM for short. When Java programs run on the JVM, objects are created on the heap, which is a portion of memory dedicated to the program. Eventually, some objects will no longer be needed. The garbage collector finds these unused objects and deletes them to free up memory. How Java Garbage Collection Works Java garbage collection is an automatic process. The programmer does not need to explicitly mark objects to be deleted. The garbage collection implementation lives in the JVM. Each JVM can implement garbage collection however it pleases; the only requirement is that it meets the JVM specification. Although there are many JVMs, Oracle’s HotSpot is by far the most common. It offers a robust and mature set of garbage collection options. While HotSpot has multiple garbage collectors that are optimized for various use cases, all its garbage collectors follow the same basic process. In the first step, unreferenced objects are identified and marked as ready for garbage collection. In the second step, marked objects are deleted. Optionally, memory can be compacted after the garbage collector deletes objects, so
Image of page 1
remaining objects are in a contiguous block at the start of the heap. The compaction process
Image of page 2
Image of page 3

You've reached the end of your free preview.

Want to read all 4 pages?

  • Fall '15
  • Ruby, Garbage collection, Manual memory management, Java Garbage Collection

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture

  • Left Quote Icon

    Student Picture