Chapter 26. Tuning Modules for Performance & Memory Footprint

NetBeans is, by definition, a large application, with a significant memory footprint. It is incumbent on anyone writing modules to write them responsibly, so that the user experience is not degraded. This chapter will outline some ways to do this in the context of NetBeans. For general optimization of Java code, we refer you to some of the excellent articles and books on the subject, such as Java 2 Performance and Idiom Guide by Craig Larman and Rhett Guthrie.

The limiting factor in NetBeans’ performance is memory. As objects are created in memory and then are no longer referenced, the memory footprint grows until garbage collection is run in the JVM. This means three things:

  • Modules should not create objects until they are about to be used.

  • Care should be taken not to hold references to objects that may not be used again or for a long time.

  • Once created, do my objects need to exist until NetBeans is shut down, or can they be disposed of sooner? What can I softly cache?[20]

NetBeans has a number of coding conventions and utility classes to optimize for memory footprint, which will be outlined throughout this chapter. Use them and your modules will run will in any reasonable environment. Some of the advice about use of threads is dependent on the target platform. But unless you’re far better than the authors at predicting the future, you probably want your code to work in any environment in which it might be deployed. ...

Get NetBeans: The Definitive Guide now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.