Well, Volkert van Heusden solved his problem, but to summarize:
At the beginning of the compress(byte [] in) method, we create a java.util.zip.Deflater .
We use Deflater to perform some actions, and then leave the compress() method. We are losing our link to Deflater -variable. At this point, Deflater no longer in use and is waiting for the garbage collector to kill it.
Deflater allocates both a heap of Java memory and C / C ++ / heap internal memory. The native heap memory allocated by the Deflater symbol will be held until the garbage collector Deflater.finalize Deflater.finalize Deflater.finalize method. If the garbage collector does not work fast enough (there may be a lot of free java heap memory), we may end up with a bunch of C / C ++ memory. If this happens, we get "Out of memory" -errors.
Oracle Error Report JDK-4797189 is probably related. It contains a piece of code that illustrates and reproduces the problem:
public class Bug { public static void main( String args[] ) { while ( true ) { final Deflater deflater = new Deflater( 9, true ); final Inflater inflater = new Inflater( true ); } } }
The solution is to free up resources when you are done by calling the Deflater.end() method (or Inflater.end() ).
andrel
source share