Kayakers and canoeists are not quite mortal enemies, but there's a healthy rivalry
between them. As a child I canoed, but I made the switch to kayaks attracted by
their stability, speed, and grace. I am now on an extended trip with three other
kayakers--and one canoeist. The canoeist, Randy Barnes, and I spar verbally at
every opportunity. I comment on his strong swimming skills, regretting that a
canoe is so difficult to roll. Randy wonders aloud why I need the security blanket
of a two-blade paddle when a canoeist can make do with a short, single blade.
Our first day is spent on the Little River, a tight, technical run in the Smokey
Mountains. I secretly marvel as Randy takes his canoe down a violent Class V
rapid called the Sinks. I decide to walk around it; for me, the margin of safety is
too slim. With outstanding control and incredible skill, Randy maneuvers his 12-
foot canoe into places I have trouble taking my 7-foot kayak.
We are now running a Class IV+ rapid known as the Elbow. It's an extremely
tight flume of water—in places just four feet wide. Bent tightly at two points, the
Elbow drops nearly 20 feet down a 40-degree fall. Three kayakers at the bottom
watch, stunned, as Randy's canoe hits the side of the chute, then the riverbed. The
canoe tumbles all the way to the end of the run. Coughing up river water, Randy
emerges as the kayakers jeer. Looking over the rapid as I prepare for my run, I
Understanding memory leaks and antipatterns
In this chapter, we'll begin to explore antipatterns related to memory leaks.
Some of you might think that memory-management discussions should be left
to JVM vendors. Technically, a Java memory leak occurs when an object can-
not be reached and it's not freed through an automatic process known as gar-
bage collection. In this sense, the virtual machine vendors, rather than
application programmers, should be the ones to concern themselves with
memory leaks. However, we'll use the term memory leak in a much broader
sense. For our purposes, an object that's not garbage-collected after it's no
longer of use to an application is a memory leak. Some of you might consider
this usage inaccurate, because Java is working precisely as it is designed. I
chose the term memory leak because it best describes the behavior of the
applications that suffer from these antipatterns: memory that we no longer
need is not returned to the memory heap and will continue to “leak” away
until we explicitly trace the source and fix the problem.
First, we'll examine memory management for other languages, such as C ++ .
We'll also examine several garbage-collection techniques and identify the ones
most JVM s use. In some places, we need to help the garbage collector to do its