应该close
其他像connection , statement,resultset用完都应该马上关闭

解决方案 »

  1.   

    you can use WeakReference/SoftReference
    http://developer.java.sun.com/developer/TechTips/1999/tt0511.html
    Reference ObjectsIn the Java programming language, the term "reference" usually refers to addresses of objects, for example, in passing an object argument (by reference) to a method that has a reference parameter. Java 2 software introduces another use of the term, the Reference class. An object of one of the Reference classes (WeakReference, SoftReference, PhantomReference) contains a "referent." The referent is an arbitrary Java object of any type. In other words, a Reference object is a wrapper for a reference. It's somewhat analogous to an Integer object being a wrapper for an integer. The reason why this feature is important is that the Java garbage collector knows about the Reference classes, and interacts with them. To see how this works, consider an example:   
    import java.lang.ref.*;
      
    public class ref {
      static Reference weakref;
      
      static void f() {
        String s = new String("abc");
        weakref = new WeakReference(s);
      }
      
      public static void main(String args[]) {
    // create garbage (a String with no references to it)
        f();
      
        System.out.println("Before GC = " 
          + weakref.get());
      
    // run garbage collector until no
    // more memory freed up
        Runtime rt = Runtime.getRuntime();
        long free = rt.freeMemory();
        long oldfree;
        do {
          oldfree = free;
          rt.gc();
          free = rt.freeMemory();
        } while (free > oldfree);
      
        System.out.println("After GC = " 
          + weakref.get());
      }
    }This program starts up and immediately calls method f, which in turn, creates a string. There are situations where an application would like to have some control over the process of garbage collection, and the Reference classes offer this. In the example above, a WeakReference object is set up, with the string as its referent. When the method returns, the string is garbage (except for the WeakReference object referring to it). But the garbage collector has not run yet, and so the referent of the WeakReference object is accessible via the get method. Then the garbage collector runs, iterating until no additional memory is freed. The referent is checked again, and this time it's null. In other words, when garbage collection occurs, the referent is "cleared." It's also possible to specify a queue for the Reference object. The Reference object is added to the queue ("enqueued") at some point after the referent is cleared. This might not seem like very much, but it's quite useful in a variety of applications. For example, one of the collection classes in the Java 2 platform, WeakHashMap, makes use of WeakReference objects. A WeakHashMap has the property that keys in the map are discarded when no longer in use. Or to say it more precisely, unused keys are subject to being discarded when the garbage collector runs. Conceptually, this mechanism is implemented by using a WeakReference object as a wrapper on the actual key, and then periodically examining a queue of WeakReference objects whose referents (the actual keys) have been cleared by the garbage collector. Another example is the use of SoftReference objects, whose referents are cleared before the Java1 Virtual Machine throws an OutOfMemory error. You can use this type of Reference object to implement caches, where a cached data structure is normally saved, but may be given up by the garbage collector in response to memory demand.  The JDC Tech Tips are written by Glen McCluskey. 
      

  2.   

    在J2EE里能见到五个星,牛!!!
      

  3.   

    用jprobe
    debug一下,尽可能的处理掉无用的对象。
      

  4.   

    也有可能是你的程序需要比较多的内存,可以给java.exe带参数增加它使用的内存
    -Xmxn Specify the maximum size, in bytes, of the memory allocation pool. This value must a multiple of 1024 greater than 2MB. Append the letter k or K to indicate kilobytes, or m or M to indicate megabytes. The default value is 64MB. The upper limit for this value will be approximately 4000m on Solaris 7 and Solaris 8 SPARC platforms and 2000m on Solaris 2.6 and x86 platforms, minus overhead amounts. Examples:        -Xmx83886080
      

  5.   

    1.不关闭不会导致outofmemory。
    2.但你必须得关闭,因为他会占用资源句柄。