2017-10-23 7 views
2

InstantSearch Androidを使用しているときにメモリリークが表示されます。InstantSearch-Androidを使用しているときにMemoryLeakが表示される

メモリをリークするMainActivityを参照してください。hprofは、com.algolia.instantsearch.ui.views.Hitsに問題があることを示しています。 Activityが破壊されたときに誰もそのViewを破壊する方法を知っていますか?ここ

public class MainActivity extends AppCompatActivity { 
    private Searcher searcher; 
    InstantSearch helper; 

    Hits hits; 

    LinearLayout activity_main; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 

     hits= (Hits) findViewById(R.id.hits); 
     activity_main= (LinearLayout) findViewById(R.id.activity_main); 

     searcher = Searcher.create("app_id","secret_key","Items"); 
     helper = new InstantSearch(this, searcher); 
     helper.search(); 
    } 

    @Override 
    protected void onDestroy() { 
     searcher=null; 

     helper=null; 
     hits.clear(); 

     hits.removeAllViewsInLayout(); 
     hits.removeAllViews(); 
     hits.destroyDrawingCache(); 
     hits.setBackground(null); 
     hits.setBackgroundResource(0); 
     hits=null; 

     activity_main.removeAllViewsInLayout(); 
     activity_main.removeAllViews(); 
     activity_main.destroyDrawingCache(); 
     activity_main.setBackground(null); 
     activity_main.setBackgroundResource(0); 
     activity_main=null; 
     Log.i("AppInfo","Destroy"); 
     super.onDestroy(); 
    } 
} 

は私activity_main.xmlです:

<LinearLayout 
android:id="@+id/activity_main" 
xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:orientation="vertical" 
android:background="@color/white" 
xmlns:algolia="http://schemas.android.com/apk/res-auto"> 


<com.algolia.instantsearch.ui.views.Hits 
    android:id="@+id/hits" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    algolia:itemLayout="@layout/hits_item" 
    algolia:autoHideKeyboard="true" 
    algolia:hitsPerPage="20"/> 

ここに私のhits_item.xmlです:

<layout xmlns:algolia="http://schemas.android.com/apk/res-auto"> 

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content"> 

     <ImageView 
      android:id="@+id/profImg" 
      android:layout_width="120dp" 
      android:layout_height="120dp" 
      android:src="@drawable/placeholder_video" 
      algolia:attribute='@{"profilePic"}'/> 

    <TextView 
     android:id="@+id/hit_title" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     algolia:attribute='@{"name"}' 
     algolia:highlighted='@{true}'/> 

</RelativeLayout> 

+0

あなたは 'InstantSearch'と' Searcher' – Soham

+1

InstantSearchとサーチャーがInstantSearchAndroid – bojan

+0

からクラスであるかのようないくつかの詳細情報を追加してくださいすることができ見ることができますサンプルアプリケーションのいずれかで同じ問題がありますか? https://github.com/algolia/instantsearch-android-examples – PLNech

答えて

7

私達はちょうど修正をリリースします。 1.1.4にアップデートすると、問題を修正できるようになりました。ちょうどあなたの活動のonDestroy次のコードを追加します。

@Override 
protected void onDestroy() { 
    // ... your code ... 
    searcher.destroy(); // This will clean and release different listeners 
    super.onDestroy(); 
} 

は、あなたはそれがhere

+0

私は非常に感謝してくれてありがとう!しかし、1.1.4で更新すると、アプリケーションが再構築できなくなり、次のメッセージが表示されます。エラー:タスク ':app:compileDebugJavaWithJavac'の実行に失敗しました。 > java.lang.RuntimeException:データバインディングエラーが見つかりました。 **** /データバインディングエラー**** msg:android.widget.TextViewのパラメータ型java.lang.Stringで属性 'algolia:attribute'のセッターを見つけることができません。 ファイル:D:\ MaterialDesign4-poslednje30 \ app \ src \ main \ res \ layout \ hits_item.xml loc:91:33 - 91:39 **** \データバインディングエラー****してくださいそれが何であるかを知っている、なぜこれは今起こっているのですか? – bojan

+0

あなたはどのAndroid Studioのバージョンを使用していますか? –

+0

@bojan前回この問題はAndroidスタジオ3.0で確認しましたが、現在1.1.4で修正されています。https://github.com/algolia/instantsearch-android/issues/47 –

関連する問題