Some classes implement the Object.finalize()
method. Objects which override this method need to called by a background thread call finalizer, and they can't be cleaned up until this happens. If these tasks are short and you don't discard many of these it all works well. However if you are creating lots of these objects and/or their finalizers take a long time, the queue of objects to be finalized builds up. It is possible for this queue to use up all the memory.
The solution is
- don't use finalize()d objects if you can (if you are writing the class for the object)
- make finalize very short (if you have to use it)
- don't discard such objects every time (try to re-use them)
The last option is likely to be best for you as you are using an existing library.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…