concern. Table 6.4 offers some guidance as to whether memory leaks should
be fixed at all.
Table 6.4 In some circumstances, fixing a memory leak may not be worth the effort. This table
shows common memory leak characteristics, and provides a guideline for whether the fix will be
Short application life cycle.
Garbage collection may never be run.
Very small footprint.
The leak should be fixed only if the application
has a long enough life for the cumulative leaks
to be a problem.
Fixing hurts code readability.
Readability is not the overriding concern,
but may discourage fixing a leak in some
Footprint is large.
The leak should be fixed if the application life
cycle is long or if resources are likely to become
Fix is very easy.
A memory leak is a bug. If the fix has been iden-
tified and has no other side effects, it should be
Code runs 24x7.
The leak will eventually become a problem.
Code is a target for reuse.
Regardless of other characteristics, if the code
is a reuse target, it should be fixed
You should be especially vigilant about fixing leaks in two instances: when an
application runs 24x7, and when code is a target for reuse. Leaks in either cir-
cumstance should nearly always be plugged. In any case, to prevent the spread
of bugs through cut and paste, if a leak exists and you don't fix it, then you
should at least document it.
Isolate the problem
Once you've determined there is a leak, and that the leak should be fixed, you
need to isolate a test case that creates the problem. Effective testing can be
much more productive than the use of low-level memory debuggers, so it's
important to make the test case as narrow as possible. Unfortunately, that isn't
always possible. The complexity of user scenarios and the degree of coupling
between elements of the application will collectively determine how effectively