Bitter Java by Bruce Tate
Author:Bruce Tate [Tate, Bruce]
Language: eng
Format: epub, pdf
Tags: General, Computers, Programming Languages, Java (Computer Program Language), Java, Programming, Software Development & Engineering
ISBN: 9781930110434
Publisher: Manning
Published: 2002-03-01T17:40:44+00:00
Shooting memory leaks
165
Iterate
When you find a problem, fix it and start over. Patching one leak can solve others as well. Many leaks are interrelated—sometimes in surprising ways—
and you’ll find it much easier to fix links one at a time than to try to solve them all with a single pass.
Fixing leaks usually turns out to be relatively easy after you’ve identified a problem. You must make the object unreachable by using one of the techniques described in this chapter. These techniques can make an object unreachable, and thus a candidate for garbage collection:
Fixing Java application memory leaks
When an object with a long life cycle maintains a reference to an object with a short life cycle, we have the potential for a memory leak. These possible fixes remove references to make an object unreachable and eligible for garbage collection.
I
Remove the object reference directly by setting it to another value.
I
Remove an object from a collection.
I
Weaken the references using Java reference objects.
I
Shorten the life cycle of the referent.
I
Shorten the life cycle of the object.
I
Remove the object from the code.
I
Refactor the code.
6.5.5
Protect against the problem for the future
When coding problems occur, you should examine the cause. If the problem is an isolated case of programming error, no further action may be necessary.
These steps will help keep the problem from occurring in the future: I
Add to the test suite to make sure that the new case is covered. This will ensure that if the problem crops up again through poor change control or cut and paste, it will be found.
I
If the problem has occurred in the past, an antipattern should be documented and shared.
I
If the antipattern or solution lends new significant insight, it should be published at some level. Publishing paths can be as focused as emails to peers or presentations in department meetings, and as broad as writing a book or speaking at a conference.
Antipatterns work best when we establish a pattern, solve a problem in a general way, and disseminate the wisdom.
Download
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
The Mikado Method by Ola Ellnestam Daniel Brolund(25279)
Hello! Python by Anthony Briggs(24329)
Secrets of the JavaScript Ninja by John Resig Bear Bibeault(23419)
Kotlin in Action by Dmitry Jemerov(22500)
The Well-Grounded Java Developer by Benjamin J. Evans Martijn Verburg(21952)
Dependency Injection in .NET by Mark Seemann(21835)
OCA Java SE 8 Programmer I Certification Guide by Mala Gupta(20697)
Algorithms of the Intelligent Web by Haralambos Marmanis;Dmitry Babenko(19514)
Grails in Action by Glen Smith Peter Ledbrook(18592)
Adobe Camera Raw For Digital Photographers Only by Rob Sheppard(17028)
Sass and Compass in Action by Wynn Netherland Nathan Weizenbaum Chris Eppstein Brandon Mathis(15836)
Secrets of the JavaScript Ninja by John Resig & Bear Bibeault(13683)
Test-Driven iOS Development with Swift 4 by Dominik Hauser(11845)
Jquery UI in Action : Master the concepts Of Jquery UI: A Step By Step Approach by ANMOL GOYAL(11149)
A Developer's Guide to Building Resilient Cloud Applications with Azure by Hamida Rebai Trabelsi(10619)
Hit Refresh by Satya Nadella(9185)
The Kubernetes Operator Framework Book by Michael Dame(8560)
Exploring Deepfakes by Bryan Lyon and Matt Tora(8398)
Robo-Advisor with Python by Aki Ranin(8344)