Memory leak? why java.lang.ref.Finalizer has so much memory

I ran a bunch of heaps in my program. When I opened it in the memory analyzer tool, I found that java.lang.ref.Finalizer for org.logicalcobwebs.proxool.ProxyStatement takes up a lot of memory. Why is this so?

screenshot

+51
java memory finalizer proxool
Dec 02 '11 at 10:40
source share
2 answers

Some classes implement the Object.finalize() method. Objects that override this method must be called by the background thread finalizer, and they cannot be cleaned up until this happens. If these tasks are short, and you do not give up many of them, everything works well. However, if you create a lot of these objects and / or their finalizers take a lot of time, the queue of objects that will be completed accumulates. This queue can use all memory.

Decision

  • don't use finalize () d objects if you can (if you are writing a class for an object)
  • make it very short (if you need to use it)
  • do not discard such objects each time (try reusing them)

The latter option is likely to be better for you, since you are using an existing library.

+49
Dec 02 2018-11-12T00:
source share

From what I can parse, Proxool is a connection pool for JDBC connections. This suggests that the problem is that your application is not using the connection pool correctly. Instead of calling close on operator objects, your code probably discards them and / or their parent connections. Proxool relies on finalizers to close the underlying objects implemented by the driver ... but this requires instances of Finalizer. It may also mean that you force the connection to open / close (real) database connections more often than necessary, and that would be bad for performance.

Therefore, I suggest that you check your code for missing ResultSet, Statement, and / or Connection objects and make sure that you close them in finally blocks.




Looking at a memory dump, I expect you to be worried about where 898 527 228 bytes go. The vast majority are stored by a Finalizer object whose id is 2aab07855e38 . If you still have a dump file, see what Finalizer means. This looks more problematic than Proxool objects.

+7
Dec 02 2018-11-11T00:
source share



All Articles