Sun Java Solaris Communities My SDN Account Join SDN
 

JavaOne Online Technical Sessions

Pump Up Your Technical Knowledge
Listen and watch as industry luminaries bring you the latest on Java technologies
Begin Product Tab Sub Links Active Sub LinkJavaOne Technical Sessions JavaOne Hands-on Labs

Garbage-Collection-Friendly Programming
TS-2906


Presenter: John Coomes, Sun Microsystems, Inc.; Peter Kessler, Sun Microsystems, Inc.; Antonios Printezis, Sun Microsystems, Inc.


Developers often ask this session's speakers for advice on how to write code that is more garbage-collection-friendly. Most of the time, their advice is: don't believe the urban myths, and don't do anything special, because trying to be smart is likely to confuse, instead of help, garbage collectors. Having said that, over the years, they have developed a small set of rules of thumb they give customers to help them with garbage-collection-related issues. This presentation summarizes them.

It starts with a very brief overview of garbage-collection terminology, to refresh the audience's memory. The overview covers only concepts that are touched on during the session, including the characteristics of generational and incremental garbage collectors.

The remainder of the presentation is split into three sections:

Section 1: General advice--This section covers some general programming advice on how not to get in the way of the garbage collector, such as the following:

  • Object allocation is very cheap, so don't be afraid of it.
  • The use of object pools should be avoided, except in special circumstances.
  • Reference nulling is largely unnecessary, except on a few very specific occasions.

The next two sections cover garbage-collection-related features of the Java programming language.

Section 2: Finalizers--Blind use of finalization can put unnecessary load on the garbage collector. This section covers traps a programmer can easily fall into when using finalization and how to avoid such traps.

Section 3. References--This section gives an overview of the three reference types of the Java programming language, advises which type to use when, and illustrates different usage patterns.

Wherever possible, concrete demos illustrate pathologies in programs that stress the GC and show how they can be rectified.

Watch The Session
You need to be a registered Sun Developer Network member to view this multimedia session. If you are a registered SDN member, please click on "Watch Multimedia" button to log-in to view the multimedia session. If you wish to join SDN, please click here.

 
 
FREE White Papers on Java SE, Java EE, cloud computing and database technologies.
New SDN Member Only Offers Every Month Discounts, FREE white papers and more!
Java University and JavaOne Training Sessions

Oracle is reviewing the Sun product roadmap and will provide guidance to customers in accordance with Oracle's standard product communication policies. Any resulting features and timing of release of such features as determined by Oracle's review of roadmaps, are at the sole discretion of Oracle. All product roadmap information, whether communicated by Sun Microsystems or by Oracle, does not represent a commitment to deliver any material, code, or functionality, and should not be relied upon in making purchasing decisions. It is intended for information purposes only, and may not be incorporated into any contract.