diff --git a/examples/demo-apps/android/LlamaDemo/app/src/main/java/com/example/executorchllamademo/MainActivity.java b/examples/demo-apps/android/LlamaDemo/app/src/main/java/com/example/executorchllamademo/MainActivity.java index 524b4fbc8a8..8bd9d8cb4f1 100644 --- a/examples/demo-apps/android/LlamaDemo/app/src/main/java/com/example/executorchllamademo/MainActivity.java +++ b/examples/demo-apps/android/LlamaDemo/app/src/main/java/com/example/executorchllamademo/MainActivity.java @@ -107,10 +107,6 @@ public void onStats(float tps) { } private void setLocalModel(String modelPath, String tokenizerPath, float temperature) { - if (mModule != null) { - mModule.resetNative(); - mModule = null; - } Message modelLoadingMessage = new Message("Loading model...", false, MessageType.SYSTEM, 0); ETLogging.getInstance().log("Loading model " + modelPath + " with tokenizer " + tokenizerPath); runOnUiThread( @@ -119,6 +115,12 @@ private void setLocalModel(String modelPath, String tokenizerPath, float tempera mMessageAdapter.add(modelLoadingMessage); mMessageAdapter.notifyDataSetChanged(); }); + if (mModule != null) { + ETLogging.getInstance().log("Start deallocating existing module instance"); + mModule.resetNative(); + mModule = null; + ETLogging.getInstance().log("Completed deallocating existing module instance"); + } long runStartTime = System.currentTimeMillis(); mModule = new LlamaModule(