Dispose object Graphics2D if it isn't used (#5876)

This commit is contained in:
lishaoxia1985 2021-12-30 13:18:12 +08:00 committed by GitHub
parent 1a8a86cb2c
commit 1d40b8a7de
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -6,7 +6,7 @@ import java.awt.*
import java.awt.image.BufferedImage
class NativeFontDesktop(val size: Int) : NativeFontImplementation {
class NativeFontDesktop(private val size: Int) : NativeFontImplementation {
private val font by lazy {
Font("", Font.PLAIN, size)
}
@ -14,7 +14,9 @@ class NativeFontDesktop(val size: Int) : NativeFontImplementation {
val bi = BufferedImage(1, 1, BufferedImage.TYPE_4BYTE_ABGR)
val g = bi.createGraphics()
g.font = font
g.fontMetrics!!
val fontMetrics = g.fontMetrics
g.dispose()
fontMetrics
}
override fun getFontSize(): Int {
@ -42,6 +44,7 @@ class NativeFontDesktop(val size: Int) : NativeFontImplementation {
pixmap.drawPixel(i, j)
}
}
g.dispose()
return pixmap
}
}