Francisco Spaeth
Francisco Spaeth

Reputation: 23903

java.lang.ref.Finalizer OutOfMemory After Memory Raise

Extracting a heapdump I realized it has a lot of objects waiting finalization, most of them are instances from libraries like jdbc connections and so on.

Knowing that those instances on the queue are basically classes that implements finalize(), why would they simply not be finalized?

A few days ago I raised the memory of such instance. Initially it had 1GB with new generation set to 256 MB (-Xmx1g -XX:NewSize=256m -XX:MaxNewSize=256m). As we added some heavy caching functionalities we raised the memory assigned to that instance to 3 GB (-Xmx3G -XX:NewSize=512m -XX:MaxNewSize=512m). From that moment we start to see some out of memories. Investigating it a bit I found out a lot of java.lang.ref.Finalizer and objects waiting for finalization.

How could this be related to each other? May it be even related?

Upvotes: 2

Views: 2776

Answers (2)

AlexC
AlexC

Reputation: 1415

Object.finalize() is called by the garbage collector on final step of the cleanup. The GC runs periodically (depending on which GC you are using, if 7 and 8 it's probably CMS, or G1 if you so configured). Having a lot of objects in 'waiting finalization' may mean that you have a large heap and enough memory that the GC did not need to run (CMS most likely, as G1 runs micro cleanups a lot more frequently).

Add GC tracing to your JVM startup parameters and monitor how often it runs: -XX:+PrintGCDetails -XX:+PrintGCTimeStamps See: http://www.oracle.com/technetwork/java/javase/gc-tuning-6-140523.html

If you are using lots of small objects with a heap >1Gb you may want to consider using the G1 garbage collector as it is better suited for such a task and doesn't have the 'stop the world' behavior of CMS.

Upvotes: 2

Peter Lawrey
Peter Lawrey

Reputation: 533530

why would they simply not be finalized?

Some components take longer to finalize esp anything which involves IO. JDBC connections are relatively heavy weight network resources so they take even longer.

I suggest you use a connection pool (most JDBC libraries have them built in) This way you are not creating/destroying them all the time.

Note: to clarify 1Gb = 1 gig-bit or 128 MB (Mega-bytes) 256 mb is 256 milli-bits or about 1/4 of a bit. -XX:NewSize=512m is 512 MB not 256 MB. and -XX:MaxNewSize=512 wouldn't work as it is just 512 bytes, most likely you used -XX:MaxNewSize=512m

3Gb is 3 giga-bits but assuming you meant 3 GB it is not -Xmx1G which is 1 GB or 8 Gb.

Upvotes: 3

Related Questions