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. ------------- Commit messages: - 7001133: OutOfMemoryError by CustomMediaSizeName implementation Changes: https://git.openjdk.org/jdk/pull/16167/files Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=16167&range=00 Issue: https://bugs.openjdk.org/browse/JDK-7001133 Stats: 173 lines in 5 files changed: 153 ins; 13 del; 7 mod Patch: https://git.openjdk.org/jdk/pull/16167.diff Fetch: git fetch https://git.openjdk.org/jdk.git pull/16167/head:pull/16167 PR: https://git.openjdk.org/jdk/pull/16167