Skip to content

Commit

Permalink
Dispose object Graphics2D if it isn't used (#5876)
Browse files Browse the repository at this point in the history
  • Loading branch information
lishaoxia1985 committed Dec 30, 2021
1 parent 1a8a86c commit 1d40b8a
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions desktop/src/com/unciv/app/desktop/NativeFontDesktop.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,17 @@ 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)
}
private val metric by lazy {
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 {
Expand Down Expand Up @@ -42,6 +44,7 @@ class NativeFontDesktop(val size: Int) : NativeFontImplementation {
pixmap.drawPixel(i, j)
}
}
g.dispose()
return pixmap
}
}

0 comments on commit 1d40b8a

Please sign in to comment.