RFR: 7001133: OutOfMemoryError by CustomMediaSizeName implementation

Phil Race prr at openjdk.org
Thu Dec 14 21:34:41 UTC 2023


On Thu, 12 Oct 2023 15:51:28 GMT, Alexander Scherbatiy <alexsch at openjdk.org> wrote:

> Each time `CUPSPrinter.initMedia()` method is called it creates new `CustomMediaSizeName` objects which are all collected in static `CustomMediaSizeName.customEnumTable` field. A lot of created duplicated `CustomMediaSizeName` objects wastes java heap space and can lead to `PrintService.getAttributes()` method call time degradation especially when a lot of different printers are installed in the operation system.
> The same is true for `CustomMediaTray` class.
> 
> The fix adds a `create()` method and a hash map which allows to reuse created  `CustomMediaSizeName/CustomMediaTray` objects. It seems that adding `equals(...)` method to `CustomMediaSizeName/CustomMediaTray` classes violates parent `Media` class contract which compares media objects only by `value` fields. The fix adds inner classes which are used as a key in corresponding hash maps.
> 
> `test/jdk/javax/print` and `test/jdk/java/awt/print` automated tests were run to check the fix on Linux and macOS.

I thought your fix is still useful, even if the problem isn't visible any more.
That's why I wrote 
"Right now, I'm inclined to suggest you push the fix you have (modulo my existing comments that need to be addressed)"

-------------

PR Comment: https://git.openjdk.org/jdk/pull/16167#issuecomment-1856656710


More information about the client-libs-dev mailing list