Skip to content

Commit

Permalink
Fix resource leak on onDestroy
Browse files Browse the repository at this point in the history
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
  • Loading branch information
matsuza authored and yukawa committed Jan 1, 2015
1 parent 1ffe8c9 commit 60de307
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,12 @@ public boolean handleMessage(Message msg) {
*/
@SuppressLint("HandlerLeak")
private class SendSyncDataCommandHandler extends Handler {

/**
* "what" value of message. Always use this.
*/
static final int WHAT = 0;

/**
* The current period of sending SYNC_DATA is 15 mins (as same as desktop version).
*/
Expand Down Expand Up @@ -648,6 +654,13 @@ public void onDestroy() {
if (sessionExecutor != null) {
sessionExecutor.syncData();
}

// Following listeners/handlers have reference to the service.
// To free the service instance, remove the listeners/handlers.
sharedPreferences.unregisterOnSharedPreferenceChangeListener(sharedPreferenceChangeListener);
sendSyncDataCommandHandler.removeMessages(SendSyncDataCommandHandler.WHAT);
memoryTrimmingHandler.removeMessages(MemoryTrimmingHandler.WHAT);

super.onDestroy();
}

Expand Down Expand Up @@ -676,7 +689,7 @@ void onCreateInternal(ViewEventListener eventListener, @Nullable ViewManagerInte

// Start sending SYNC_DATA message to mozc server periodically.
sendSyncDataCommandHandler.sendEmptyMessageDelayed(
0, SendSyncDataCommandHandler.SYNC_DATA_COMMAND_PERIOD);
SendSyncDataCommandHandler.WHAT, SendSyncDataCommandHandler.SYNC_DATA_COMMAND_PERIOD);
this.sharedPreferences = sharedPreferences;
}

Expand Down
2 changes: 1 addition & 1 deletion src/mozc_version_template.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MAJOR=2
MINOR=16
BUILD=2007
BUILD=2008
REVISION=102
# NACL_DICTIONARY_VERSION is the target version of the system dictionary to be
# downloaded by NaCl Mozc.
Expand Down

0 comments on commit 60de307

Please sign in to comment.