marian mocanu | Dreamstime
65df858fee7fb2001ef175aa 0324eiedarticle 1 Promo Marian Mocanu Dreamstime X

Garbage Collection: Memory Waste Management

March 4, 2011
Memory management is central to every program. Garbage collection usually addresses the problem better than explicit waste management.

Memory management is central to every program. Dangling pointers due to improper memory management procedures are among the banes of C and C++. Automatic free memory management, or garbage collection, is inherent to platforms like Java and Microsoft’s .NET. In the latter, “managed” applications like those written in C# utilize garbage collection. 

Around for ages, garbage collection was used early on by Lisp. Java and .NET are the current mainstream solutions that employ it. Garbage collection doesn’t completely eliminate memory-related programming errors, but it does remove many issues like uninitialized or dangling pointers.

Garbage Myths And Facts

Java and C# programmers tend to take garbage collection as fact, but many others look at it with disdain usually because they misunderstand the technology. For example, many programmers wouldn’t consider using garbage collection in real-time applications because of the pause it requires. This is true for stop-mark-sweep garbage collectors. These days, most systems employ concurrent, generational garbage collectors that suit interactive and real-time environments (see the figure).

Likewise, there is an assumption that garbage collection has significant overhead and skilled programmers can always do better using explicit allocation. There were similar arguments comparing assembly language to high-level languages, but it’s now hard to find a programmer who even knows what assembly language is. This is true even for embedded programmers. The truth is that garbage collection provides better performance in general than explicit memory management.

Collective Variations

Looking under the hood of a garbage collection system is a major effort, which is why these systems tend to be black boxes for most programmers. There are many variations, such as stop-the-world, incremental, and concurrent collection methodologies. There are also variations such as in-place, copy, and compacting garbage collection. 

The interesting aspect of these considerations is that they affect performance and overhead but usually do not affect the languages that utilize garbage collection. Garbage collection technology has also moved past simple allocate/dereference protocols. Java and .Net support dispose and finalize semantics, enabling programmers to provide class methods for objects to handle how an object goes away.

A program can call dispose while the garbage collector calls finalize. Dispose provides a shutdown mechanism, while finalize is called just before the object is returned to free space. These methods can be used to release resources that may not be managed by the memory system. For example, a finalization method might release a window handle or communication connection.

Embedded, Real-time Garbage

Atego’s aonixPerc and Oracle’s Sun Real Time Java are two Java implementations that provide real-time garbage collection. Microsoft’s .NET also provides a selection of garbage collectors for developers to employ. 

Azul Systems targets the enterprise with its Java solution, which uses its Pauseless Garbage Collection. The company also is sponsoring the open-source Managed Runtime Initiative, which addresses garbage collection as just one of its issues.

Efficient garbage collection can take advantage of features such as virtual memory support that might otherwise be unavailable to applications. Having access to these facilities in a controlled fashion would allow platforms like Azul’s Zing to run on a range of operating systems.

Managed environments like Java and .Net are becoming more desirable for embedded applications if you know what to look for—or, in the case of garbage collection, letting the system look for it.

Atego
www.atego.com
Azul Systems
www.azulsystems.com
Microsoft
www.Microsoft.com
Oracle
www.oracle.com

About the Author

William G. Wong | Senior Content Director - Electronic Design and Microwaves & RF

I am Editor of Electronic Design focusing on embedded, software, and systems. As Senior Content Director, I also manage Microwaves & RF and I work with a great team of editors to provide engineers, programmers, developers and technical managers with interesting and useful articles and videos on a regular basis. Check out our free newsletters to see the latest content.

You can send press releases for new products for possible coverage on the website. I am also interested in receiving contributed articles for publishing on our website. Use our template and send to me along with a signed release form. 

Check out my blog, AltEmbedded on Electronic Design, as well as his latest articles on this site that are listed below. 

You can visit my social media via these links:

I earned a Bachelor of Electrical Engineering at the Georgia Institute of Technology and a Masters in Computer Science from Rutgers University. I still do a bit of programming using everything from C and C++ to Rust and Ada/SPARK. I do a bit of PHP programming for Drupal websites. I have posted a few Drupal modules.  

I still get a hand on software and electronic hardware. Some of this can be found on our Kit Close-Up video series. You can also see me on many of our TechXchange Talk videos. I am interested in a range of projects from robotics to artificial intelligence. 

Sponsored Recommendations

Comments

To join the conversation, and become an exclusive member of Electronic Design, create an account today!