0
votes

I'm doing a project realted to JVM GC and I was planning to replace JVM automatic GC with my manual GC.

I know that JAVA has an automatic garbage collector. What if we integrate a new manual garbage collector where the developer need to explictly call new and delete on objects (like in C++).

Lets assume that the programmer write the free without memory leak.

Would it be efficient to use manual garbage collector instead of automatic garbage collection?.

Is it common to use manual GC in industry? Or do programmers use automatic garbage collector everywhere?.

1
You may want to look at Epsilon GC: openjdk.java.net/jeps/318Juraj Martinka

1 Answers

3
votes

I think your project is too ambitious. For example, replacing the existing JVM GC framework with alloc / free memory management would probably entail a substantial rewrite of the JVM native code codebase AND a redesign of the Java class library.

(Did you know that a checkout of the Java 11 OpenJDK source repo is 2.5 Gbytes? There's a lot of code there. Look before you leap.)


You asked:

Would it be efficient to use manual garbage collector instead of automatic garbage collection?

In my opinion, No:

  • As was demonstrated a long time ago (see the classic Zorn paper), for large applications an automatic GC is as fast as (if not faster than) storage management using malloc/free with smart pointers.

  • The entire Java class library is designed on the assumption that GC is automatic and efficient. If you change that, then much of the current API design is problematic; i.e. it would leak heap objects.

However, if you put 10 or so man-years of skilled dev effort into the project, you may end up with a different answer. (And probably a very different programming language!)

Is it common to use manual GC in industry?

With Java it is unheard of.

In languages such as C / C++ that were not written with automatic GC in mind, it is still common to use manual storage management. (But not universal. Read about the Boehm conservative collector.)

Or do programmers use automatic garbage collector everywhere?

With Java, yes.

In many other programming languages yes. But not all languages.


Reference:

  • "The measured cost of conservative garbage collection" by Benjamin G. Zorn, Published in Softw., Pract. Exper. 1993. DOI: 10.1002/spe.4380230704