Fix graphics memory leak when keyboard recreated

This commit is contained in:
Aleksandras Kostarevas 2024-04-22 00:33:03 -04:00
parent 9e0dc28848
commit d62b733412
4 changed files with 13 additions and 2 deletions

View File

@ -291,6 +291,8 @@ public class KeyboardView extends View {
} }
private void freeOffscreenBuffer() { private void freeOffscreenBuffer() {
setLayerType(LAYER_TYPE_NONE, null);
mOffscreenCanvas.setBitmap(null); mOffscreenCanvas.setBitmap(null);
mOffscreenCanvas.setMatrix(null); mOffscreenCanvas.setMatrix(null);
if (mOffscreenBuffer != null) { if (mOffscreenBuffer != null) {

View File

@ -61,6 +61,8 @@ public final class DrawingPreviewPlacerView extends RelativeLayout {
} }
public void deallocateMemory() { public void deallocateMemory() {
setLayerType(LAYER_TYPE_NONE, null);
final int count = mPreviews.size(); final int count = mPreviews.size();
for (int i = 0; i < count; i++) { for (int i = 0; i < count; i++) {
mPreviews.get(i).onDeallocateMemory(); mPreviews.get(i).onDeallocateMemory();

View File

@ -221,4 +221,8 @@ public final class InputView extends FrameLayout {
return false; return false;
} }
} }
public void deallocateMemory() {
mMainKeyboardView.deallocateMemory();
}
} }

View File

@ -126,7 +126,6 @@ class LatinIME : InputMethodService(), LifecycleOwner, ViewModelStoreOwner, Save
private var lastEditorInfo: EditorInfo? = null private var lastEditorInfo: EditorInfo? = null
// TODO: Calling this repeatedly as the theme changes tends to slow everything to a crawl
private fun recreateKeyboard() { private fun recreateKeyboard() {
latinIMELegacy.updateTheme() latinIMELegacy.updateTheme()
latinIMELegacy.mKeyboardSwitcher.mState.onLoadKeyboard(latinIMELegacy.currentAutoCapsState, latinIMELegacy.currentRecapitalizeState); latinIMELegacy.mKeyboardSwitcher.mState.onLoadKeyboard(latinIMELegacy.currentAutoCapsState, latinIMELegacy.currentRecapitalizeState);
@ -327,7 +326,11 @@ class LatinIME : InputMethodService(), LifecycleOwner, ViewModelStoreOwner, Save
key(legacyInputView) { key(legacyInputView) {
AndroidView(factory = { AndroidView(factory = {
legacyInputView!! legacyInputView!!
}, modifier = modifier) }, modifier = modifier, onRelease = {
val view = it as InputView
view.deallocateMemory()
view.removeAllViews()
})
} }
} }