mirror of
https://github.com/HMCL-dev/HMCL.git
synced 2025-09-12 21:36:21 -04:00
修复内存泄漏 (#1888)
* Fix memory leaks * Cache icon in cell * Lazy acquisition of availableCharsets
This commit is contained in:
parent
ea91ee91ec
commit
a6231ac593
@ -141,11 +141,17 @@ public final class Controllers {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void onApplicationStop() {
|
public static void onApplicationStop() {
|
||||||
|
if (stageHeight != null) {
|
||||||
config().setHeight(stageHeight.get());
|
config().setHeight(stageHeight.get());
|
||||||
config().setWidth(stageWidth.get());
|
stageHeight.unbind();
|
||||||
stageHeight = null;
|
stageHeight = null;
|
||||||
|
}
|
||||||
|
if (stageWidth != null) {
|
||||||
|
config().setWidth(stageWidth.get());
|
||||||
|
stageWidth.unbind();
|
||||||
stageWidth = null;
|
stageWidth = null;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static void initialize(Stage stage) {
|
public static void initialize(Stage stage) {
|
||||||
Logging.LOG.info("Start initializing application");
|
Logging.LOG.info("Start initializing application");
|
||||||
@ -321,5 +327,6 @@ public final class Controllers {
|
|||||||
decorator = null;
|
decorator = null;
|
||||||
stage = null;
|
stage = null;
|
||||||
scene = null;
|
scene = null;
|
||||||
|
onApplicationStop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -127,7 +127,8 @@ public final class VersionsPage extends BorderPane implements WizardPage, Refres
|
|||||||
btnRefresh.setGraphic(wrap(SVG.refresh(Theme.blackFillBinding(), -1, -1)));
|
btnRefresh.setGraphic(wrap(SVG.refresh(Theme.blackFillBinding(), -1, -1)));
|
||||||
|
|
||||||
MutableObject<RemoteVersionListCell> lastCell = new MutableObject<>();
|
MutableObject<RemoteVersionListCell> lastCell = new MutableObject<>();
|
||||||
list.setCellFactory(listView -> new RemoteVersionListCell(lastCell));
|
EnumMap<VersionIconType, Image> icons = new EnumMap<>(VersionIconType.class);
|
||||||
|
list.setCellFactory(listView -> new RemoteVersionListCell(lastCell, icons));
|
||||||
|
|
||||||
list.setOnMouseClicked(e -> {
|
list.setOnMouseClicked(e -> {
|
||||||
if (list.getSelectionModel().getSelectedIndex() < 0)
|
if (list.getSelectionModel().getSelectedIndex() < 0)
|
||||||
@ -218,29 +219,26 @@ public final class VersionsPage extends BorderPane implements WizardPage, Refres
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static class RemoteVersionListCell extends ListCell<RemoteVersion> {
|
private static class RemoteVersionListCell extends ListCell<RemoteVersion> {
|
||||||
private static final EnumMap<VersionIconType, Image> icon = new EnumMap<>(VersionIconType.class);
|
|
||||||
|
|
||||||
private static Image getIcon(VersionIconType type) {
|
|
||||||
assert Platform.isFxApplicationThread();
|
|
||||||
return icon.computeIfAbsent(type, iconType -> new Image(iconType.getResourceUrl(), 32, 32, false, true));
|
|
||||||
}
|
|
||||||
|
|
||||||
final IconedTwoLineListItem content = new IconedTwoLineListItem();
|
final IconedTwoLineListItem content = new IconedTwoLineListItem();
|
||||||
final RipplerContainer ripplerContainer = new RipplerContainer(content);
|
final RipplerContainer ripplerContainer = new RipplerContainer(content);
|
||||||
final StackPane pane = new StackPane();
|
final StackPane pane = new StackPane();
|
||||||
|
|
||||||
private final MutableObject<RemoteVersionListCell> lastCell;
|
private final MutableObject<RemoteVersionListCell> lastCell;
|
||||||
|
private final EnumMap<VersionIconType, Image> icons;
|
||||||
|
|
||||||
RemoteVersionListCell(MutableObject<RemoteVersionListCell> lastCell) {
|
RemoteVersionListCell(MutableObject<RemoteVersionListCell> lastCell, EnumMap<VersionIconType, Image> icons) {
|
||||||
this.lastCell = lastCell;
|
this.lastCell = lastCell;
|
||||||
}
|
this.icons = icons;
|
||||||
|
|
||||||
{
|
|
||||||
pane.getStyleClass().add("md-list-cell");
|
pane.getStyleClass().add("md-list-cell");
|
||||||
StackPane.setMargin(content, new Insets(10, 16, 10, 16));
|
StackPane.setMargin(content, new Insets(10, 16, 10, 16));
|
||||||
pane.getChildren().setAll(ripplerContainer);
|
pane.getChildren().setAll(ripplerContainer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Image getIcon(VersionIconType type) {
|
||||||
|
return icons.computeIfAbsent(type, iconType -> new Image(iconType.getResourceUrl(), 32, 32, false, true));
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateItem(RemoteVersion remoteVersion, boolean empty) {
|
public void updateItem(RemoteVersion remoteVersion, boolean empty) {
|
||||||
super.updateItem(remoteVersion, empty);
|
super.updateItem(remoteVersion, empty);
|
||||||
|
@ -88,7 +88,7 @@ public final class CompressingUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static Charset findSuitableEncoding(Path zipFile) throws IOException {
|
public static Charset findSuitableEncoding(Path zipFile) throws IOException {
|
||||||
return findSuitableEncoding(zipFile, Charset.availableCharsets().values());
|
return findSuitableEncoding(zipFile, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Charset findSuitableEncoding(Path zipFile, Collection<Charset> candidates) throws IOException {
|
public static Charset findSuitableEncoding(Path zipFile, Collection<Charset> candidates) throws IOException {
|
||||||
@ -98,7 +98,7 @@ public final class CompressingUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static Charset findSuitableEncoding(ZipFile zipFile) throws IOException {
|
public static Charset findSuitableEncoding(ZipFile zipFile) throws IOException {
|
||||||
return findSuitableEncoding(zipFile, Charset.availableCharsets().values());
|
return findSuitableEncoding(zipFile, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Charset findSuitableEncoding(ZipFile zipFile, Collection<Charset> candidates) throws IOException {
|
public static Charset findSuitableEncoding(ZipFile zipFile, Collection<Charset> candidates) throws IOException {
|
||||||
@ -106,6 +106,9 @@ public final class CompressingUtils {
|
|||||||
if (OperatingSystem.NATIVE_CHARSET != StandardCharsets.UTF_8 && testEncoding(zipFile, OperatingSystem.NATIVE_CHARSET))
|
if (OperatingSystem.NATIVE_CHARSET != StandardCharsets.UTF_8 && testEncoding(zipFile, OperatingSystem.NATIVE_CHARSET))
|
||||||
return OperatingSystem.NATIVE_CHARSET;
|
return OperatingSystem.NATIVE_CHARSET;
|
||||||
|
|
||||||
|
if (candidates == null)
|
||||||
|
candidates = Charset.availableCharsets().values();
|
||||||
|
|
||||||
for (Charset charset : candidates)
|
for (Charset charset : candidates)
|
||||||
if (charset != null && testEncoding(zipFile, charset))
|
if (charset != null && testEncoding(zipFile, charset))
|
||||||
return charset;
|
return charset;
|
||||||
@ -156,8 +159,6 @@ public final class CompressingUtils {
|
|||||||
public FileSystem build() throws IOException {
|
public FileSystem build() throws IOException {
|
||||||
if (autoDetectEncoding) {
|
if (autoDetectEncoding) {
|
||||||
if (!testEncoding(zip, encoding)) {
|
if (!testEncoding(zip, encoding)) {
|
||||||
if (charsetCandidates == null)
|
|
||||||
charsetCandidates = Charset.availableCharsets().values();
|
|
||||||
encoding = findSuitableEncoding(zip, charsetCandidates);
|
encoding = findSuitableEncoding(zip, charsetCandidates);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user