Is Java the Best Coding Choice When it Comes to GC?

Google developer Colt McAnlis recently discussed performance issues associated with Java at the O’Reilly Velocity conference in NY. He spoke about the problems with parsing engines using GC (garbage collection) to manage memory, even though it helps programmers by automatically returning to the operating system the memory a program no longer needs.

Zintro EmscriptenThe problem with many JavaScript Web applications is that JavaScript engines will launch their garbage collection routines at seemingly random times, causing a temporary slowdown. McAnlis advised against relying on GC, referring to a study that shows the system memory must be 6 times as large as the amount of memory being used in order for it to not be noticed by the user. That can be a demanding requirement considering the amount of space applications require on mobile devices that already have issues with limited memory.

McAnlis suggested that to improve performance and better manage memory, developers should use an approach similar to middleware Emscripten, which is being used to build high performance HTML5 Web games. According to JavaWorld, “Emscripten converts code written in C or C++ into JavaScript, allowing it to manage memory from within the application itself. An Emscripten-based program will pre-allocate a block of memory from the system. The programmer, along with Emscripten itself, decides when memory is no longer needed, and Emscripten returns this unused memory to its pool of internally available memory. The JavaScript engine does not do any GC on the program and so would not affect the performance of the program.”

Programming consultant Kenneth Kent has worked with coding for over 30 years. He shares his opinion about GC. “JavaScript and C++ are both useful languages. Their garbage collecting can be ‘quirky’ at best. In C++, you actually have to tell it to do the collection. As stated before, JavaScript does it at random times. This can be awkward-especially if the program needs that memory at that point. Java, on the other hand, does an excellent job of GC. At least, I think so. By moving memory in and out as the program runs, keeps a maximum amount of memory available when and where it is needed.”

Kent’s personal preference is C++. “I have programmed in all 3 languages,” he explains. Most of my programs were small and required only a small amount of memory. Given a choice, though, I much prefer C++. Although, Java is very similar and used on a larger scale, C++ is easier to work with and is becoming a very useful and accepted language.”

Zintro has experts in every industry sector, across every job function, in every geographic region. Recently, some of the following topics have seen inquiry activity: