Skip to content

Commit 60de307

Browse files
matsuzayukawa
authored andcommitted
Fix resource leak on onDestroy
Starting from Android 5.0, IME processes can be alive even after Service.onDestory is called depending on the available memory so that we can switch IMEs as fast as possible. https://android.googlesource.com/platform/frameworks/base/+/f0f94d129b6eb3c48624e915898d86d4f2de59ff However, this change revealed that Mozc has not released all the Java objects on Service.onDestory, which can be observed as an increasing memory usage of Mozc. Closes Issue 265. BUG=Issue mozc:265 TEST=manually done with Nexus 5 / Android 5.0.1 (LRX22C) git-svn-id: https://mozc.googlecode.com/svn/trunk@474 a6090854-d499-a067-5803-1114d4e51264
1 parent 1ffe8c9 commit 60de307

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

src/android/src/com/google/android/inputmethod/japanese/MozcService.java

+14-1
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,12 @@ public boolean handleMessage(Message msg) {
453453
*/
454454
@SuppressLint("HandlerLeak")
455455
private class SendSyncDataCommandHandler extends Handler {
456+
457+
/**
458+
* "what" value of message. Always use this.
459+
*/
460+
static final int WHAT = 0;
461+
456462
/**
457463
* The current period of sending SYNC_DATA is 15 mins (as same as desktop version).
458464
*/
@@ -648,6 +654,13 @@ public void onDestroy() {
648654
if (sessionExecutor != null) {
649655
sessionExecutor.syncData();
650656
}
657+
658+
// Following listeners/handlers have reference to the service.
659+
// To free the service instance, remove the listeners/handlers.
660+
sharedPreferences.unregisterOnSharedPreferenceChangeListener(sharedPreferenceChangeListener);
661+
sendSyncDataCommandHandler.removeMessages(SendSyncDataCommandHandler.WHAT);
662+
memoryTrimmingHandler.removeMessages(MemoryTrimmingHandler.WHAT);
663+
651664
super.onDestroy();
652665
}
653666

@@ -676,7 +689,7 @@ void onCreateInternal(ViewEventListener eventListener, @Nullable ViewManagerInte
676689

677690
// Start sending SYNC_DATA message to mozc server periodically.
678691
sendSyncDataCommandHandler.sendEmptyMessageDelayed(
679-
0, SendSyncDataCommandHandler.SYNC_DATA_COMMAND_PERIOD);
692+
SendSyncDataCommandHandler.WHAT, SendSyncDataCommandHandler.SYNC_DATA_COMMAND_PERIOD);
680693
this.sharedPreferences = sharedPreferences;
681694
}
682695

src/mozc_version_template.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MAJOR=2
22
MINOR=16
3-
BUILD=2007
3+
BUILD=2008
44
REVISION=102
55
# NACL_DICTIONARY_VERSION is the target version of the system dictionary to be
66
# downloaded by NaCl Mozc.

0 commit comments

Comments
 (0)